Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Transform.position return strange value

Discussion in 'Scripting' started by SayhiUnity, Jun 20, 2017.

  1. SayhiUnity


    Jan 7, 2017
    At first, sorry for my poor English.

    I meet a strange problem about Transform.position:
    documentation said Transform.position should return Gameobject's worldspace position.

    but when i do this(my English is poor, make a picture to explain):

    This result is not correct, the real World position is: realWP1.png
    why ?

    again, sorry for my English.
  2. AcePilot10


    Aug 11, 2016
    First off, GameObject.Find is pretty unsafe, maybe it's finding another object. I would recommend making a public field and drag the head object into the inspector field. That, or make the head have a tag. But for your problem, you're getting the local position (reference to the parent object) I believe. Try using Transform.TransformPoint();
  3. Scabbage


    Dec 11, 2014
    Other way around mate. transform.position is indeed giving the world position, but the inspector shows the local transform. Print the transform.localPosition and it'll be the same as in the inspector.
  4. Baste


    Jan 24, 2013
    transform.position returns the world position. I'm going to guess that Transform.Find("head") is picking up the Female model's head, since that probably has the same name. Don't use Transform.Find, you're pretty much always going to run into situations where things break because there's a new object with the same name.

    To figure out which object you're actually printing the position of, add it as a second parameter to your Debug.Log:
    Code (csharp):
    1. Debug.Log("headbone worldspace position is: " + headbone.transform.position, headbone);
    When you click that message in the inspector, the gameobject will get pinged in the hierarchy.

    An alternative explanation:
    With the 2D camera, it's really hard to see where the sphere is in relation to the head. Since 2D is ortographic, your sphere could really be hundreds of units away from the head!

    Alternative 3:
    Your skinned mesh renderer is messed up somehow, and offset very far from the bones. So your bones are around the origin, but the verts are pushed to where your sphere is. Not very likely, but idk.
  5. Wendo90


    Mar 12, 2018
    I had a similar problem with a transform position of a bone. In the end the wrong value came from setting the position in FixedUpdate(). When I moved the call in the Update() function, the position was correct.