Inspector Position not matching position obtained in script

Went to move a GameObject that contains child GameObjects, but wanted to move certain parts at different speeds/directions. Couldn’t get the results I was aiming for and finally figured out why… the positions of my parts in the inspector are not the positions I obtain in my scripts using part.transform.localPosition. Because of this, I get unexpected behaviors. Attached are screenshots of my issue:

2184290--144778--Inspector.png
2184290--144779--Readout.png

I’m running version 5.1.1f1. Any suggestions?

Yeah, I’m really not sure why this is but I’ve come to accept it as part of unity. transform.localPosition seems to always return the world-space position of the transform.

To get the local space position, try this:

Vector3 localPos = transform.position;
if (transform.parent != null)
{
    localPos -= transform.parent.position
}

If you debug log the vector3 it will show rounded values. Logging the individual axis’ will show the accurate values.

Thank you Gambit MSplitz. Ended up going that route because my parent GameObject wasn’t at the origin. Come to find out that it was the parent/child relationship (scaling) that was causing problems.