I've been working in Unity for 6 months, but still haven't figured this out!
How do I get the editor to display a Child Game Object's world position? If I right click on the Inspector View and select "Debug" then I can see the object's Local Position, but there does not seem to be any listing of the World Position.
I am currently working around this by simply dragging the GO out of the hierarchy into the root of the project to grab the number for my code. I realize there are a lot of other workarounds to this problem as well, but I feel like I must be overlooking how to do this in the editor.
You can easily add new editor menu items for this sort of debug functionality. Put this C# script in your Assets\Editor folder (or a sub-folder of Editor). You should now have a new Debug menu on the main menu bar, with a Print Global Position menu item that displays the position of the selected object.
using UnityEngine;
using UnityEditor;
public static class DebugMenu
{
[MenuItem("Debug/Print Global Position")]
public static void PrintGlobalPosition()
{
if (Selection.activeGameObject != null)
{
Debug.Log(Selection.activeGameObject.name + " is at " + Selection.activeGameObject.transform.position);
}
}
}
You could make a custom editor that displays the world position. Here's a simplified example. You would probably want to do something a little more complicated since this overrides the default view.
//WorldPosViewer.js
@CustomEditor(Transform)
class WorldPosViewer extends Editor {
function OnInspectorGUI() {
EditorGUILayout.BeginHorizontal ();
target.position = EditorGUILayout.Vector3Field("World Pos", target.position);
//this will display the target's world pos.
EditorGUILayout.EndHorizontal ();
}
}
This code is fairly simple. It just displays a Vector3 field in the Transform Component instead of the standard local coordinates. The problem I spoke of earlier is that you need to add back in the functionality for viewing the rotation and other properties since this overrides them.
You could also inspect a different component that you know your object will have then indirectly access its transform.