Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
8
Question by Thom Denick · Dec 22, 2010 at 06:56 PM · editorpositionworldglobal

How to get to the Editor to display a child's World Position?

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Peter G · Dec 22, 2010 at 08:06 PM

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.

target.transform.position = EditorGUILayout.Vector3Field();

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Stephen_O · Jan 19, 2016 at 04:00 PM 0
Share

I was originally using the syntax below to display most of my custom editors, until today I was creating one for a variable that represented an objects local transform position. The syntax I was using was displaying inconsistent values when extending the editor. I've used the syntax you listed before, but found today that in the case of local transform variables for some reason this seems to be more accurate. I can speculate as to why this happens , but anyway if you're extending local transform variables perhaps this will be useful for you too. Thanks Peter.

 SerializedProperty localPositionValue = serializedObject.FindProperty("localPositionValue ");
             EditorGUI.BeginChangeCheck();
             EditorGUILayout.PropertyField(localPositionValue , true);
             if (EditorGUI.EndChangeCheck())
                 serializedObject.Apply$$anonymous$$odifiedProperties();

avatar image
11

Answer by yoyo · Dec 23, 2010 at 04:19 AM

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);
         }
     }
 }

             
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nicloay · May 31, 2013 at 05:00 PM 0
Share

thanks for this solution, it's more convenient than to write editor for every class.

avatar image Black_Stormy · Sep 14, 2017 at 10:42 AM 0
Share

This script is great, but it is causing my cloud build to fail with the error [Unity] Assets/GlobalPositionDebu.cs(2,7): error CS0246: The type or namespace name 'UnityEditor' could not be found. Are you missing an assembly reference? When in doubt, comment it out!

avatar image Bitfabrikken Black_Stormy · Aug 12, 2018 at 06:44 AM 0
Share

That's because UnityEditor is not present when you build. The UnityEditor code blocks in your code, you should wrap with e.g.

#if UNITY_EDITOR editorcodehere #endif

It'll get ignored when you build.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Modify child's world position in editor 1 Answer

Finding Position based on a local perspective 1 Answer

TopDown Controls - World Movement 1 Answer

Get wold position of child without code. 0 Answers

how to make the object position related to the screen 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges