Transform.position return strange value

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:


why ?

again, sorry for my English.

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

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.

1 Like

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:

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.

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.

Sorry for necro but i wanted to confirm what Wendo90 said. Retrieving the world position outside late update will return the incorrect world position, explanation here: Unity Issue Tracker - Incorrect Bone Transform values are retrieved when getting them with Script. So to correct this you have to use LateUpdate() or WaitForEndOfFrame() when you retrieve the positions.