Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Can I See Global Coordinates in the Inspector?

Discussion in 'Editor & General Support' started by John-B, May 22, 2014.

  1. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,262
    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.
     
    Last edited: May 22, 2014
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you write a custom inspector, yes.

    --Eric
     
  3. Warped-Imagination

    Warped-Imagination

    Joined:
    May 18, 2014
    Posts:
    51
    Someone previously posted the custom editor code here link
     
  4. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,262
    Thanks.

    Just wondering why there's a global/local option in the scene view and not the inspector.
     
  5. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    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.
     
  6. DavidLe360

    DavidLe360

    Joined:
    Dec 24, 2018
    Posts:
    127
    bakinto, thomas4d, Aki7an and 6 others like this.
  7. ahmedpro1112

    ahmedpro1112

    Joined:
    Nov 16, 2022
    Posts:
    4
    Code (CSharp):
    1. #if UNITY_EDITOR
    2. using UnityEditor;
    3. using UnityEngine;
    4. [CustomEditor(typeof(Transform))]
    5. class TransformOverride : Editor
    6. {
    7.     public override void OnInspectorGUI()
    8.     {
    9.         Transform transform = (Transform)target;
    10.  
    11.         EditorGUILayout.LabelField("Position", EditorStyles.boldLabel);
    12.         EditorGUILayout.Vector3Field("World Position", transform.position);
    13.         EditorGUILayout.Vector3Field("Local Position", transform.localPosition);
    14.  
    15.         EditorGUILayout.LabelField("");
    16.         EditorGUILayout.LabelField("Rotation", EditorStyles.boldLabel);
    17.         EditorGUILayout.Vector3Field("Euler Angles", transform.eulerAngles);
    18.         EditorGUILayout.Vector3Field("Local Euler Angles", transform.localEulerAngles);
    19.  
    20.         EditorGUILayout.LabelField("");
    21.         EditorGUILayout.LabelField("Other", EditorStyles.boldLabel);
    22.         EditorGUILayout.Vector3Field("Scale", transform.localScale);
    23.     }
    24. }
    25. #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:
    Code (CSharp):
    1. #if UNITY_EDITOR
    2. using UnityEditor;
    3. using UnityEngine;
    4. [CustomEditor(typeof(Transform))]
    5. class TransformOverride : Editor
    6. {
    7.     public override void OnInspectorGUI()
    8.     {
    9.         Transform transform = (Transform)target;
    10.         base.OnInspectorGUI();
    11.         if (GUILayout.Button("Copy world Position"))
    12.         {
    13.             GUIUtility.systemCopyBuffer = $"Vector3{transform.position}";
    14.         }
    15.         if (GUILayout.Button("Copy World Euler Angles"))
    16.         {
    17.             GUIUtility.systemCopyBuffer = $"Vector3{transform.eulerAngles}";
    18.         }
    19.     }
    20. }
    21. #endif
     
    Last edited: Jul 10, 2023
    grbulat likes this.