Can I See Global Coordinates in the Inspector?

Is there any way to see a transform’s global coordinates (position, rotation) in the Inspector? For example, when I set an object’s transform.position in code, is there any way to see if the object is actually at that position in the Inspector? All I’ve ever been able to see in the Inspector is an object’s position/rotation relative to its parent.

1 Like

If you write a custom inspector, yes.

–Eric

Someone previously posted the custom editor code here link

Thanks.

Just wondering why there’s a global/local option in the scene view and not the inspector.

The scene view can switch between calculating object space or world space coordinates and changes them accordingly, the inspector just tells what you have and does not calculate anything (except Quaternion.eulerAngles)
The position is stored internally as transform.localPosition, transform.position should be a calculated value. At least some tests I made for vector precision suggest that.

Hi, or maybe this asset can help:

Inspector Gadgets Lite

5381010--545154--upload_2020-1-17_6-31-11.png

9 Likes
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(Transform))]
class TransformOverride : Editor
{
    public override void OnInspectorGUI()
    {
        Transform transform = (Transform)target;

        EditorGUILayout.LabelField("Position", EditorStyles.boldLabel);
        EditorGUILayout.Vector3Field("World Position", transform.position);
        EditorGUILayout.Vector3Field("Local Position", transform.localPosition);

        EditorGUILayout.LabelField("");
        EditorGUILayout.LabelField("Rotation", EditorStyles.boldLabel);
        EditorGUILayout.Vector3Field("Euler Angles", transform.eulerAngles);
        EditorGUILayout.Vector3Field("Local Euler Angles", transform.localEulerAngles);

        EditorGUILayout.LabelField("");
        EditorGUILayout.LabelField("Other", EditorStyles.boldLabel);
        EditorGUILayout.Vector3Field("Scale", transform.localScale);
    }
}
#endif

EDIT: This solution prevents you from being able to copy & paste and makes them read only (you can’t change them in the inspector).

Do this instead:

#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(Transform))]
class TransformOverride : Editor
{
    public override void OnInspectorGUI()
    {
        Transform transform = (Transform)target;
        base.OnInspectorGUI();
        if (GUILayout.Button("Copy world Position"))
        {
            GUIUtility.systemCopyBuffer = $"Vector3{transform.position}";
        }
        if (GUILayout.Button("Copy World Euler Angles"))
        {
            GUIUtility.systemCopyBuffer = $"Vector3{transform.eulerAngles}";
        }
    }
}
#endif
3 Likes