- Home /
Code thinks RectTransforms position is (0,0,0)
This is by far the weirdest experience I have had in my four years of developing in Unity.
I have a RectTransform that I'm casting as a Transform and checking for its position like so -
public Transform leftBorder;
void Awake()
{
Debug.Log(leftBorder.position);
}
Everything works fine and the position is shown correctly.
I do the exact same thing with a different RectTransform in another script and it's always showing the position as (0,0,0). I am 100% sure the position of the other transform isn't (0,0,0) and even if I change its local position the result stays the same. Both RectTransforms are inside the same Canvas and seem to be the same to me.
What could be causing this?
Answer by Artifact-Jesse · Aug 20, 2016 at 08:53 AM
My best guess is that your pivot and anchor are in the same position. Since RectTransform.position gives you the position of your RectTransform's pivot relative to its anchor (I think), your RectTransform's position is reading 0,0.
But you'll have to tell us what your pivot/anchor setup is for the RectTransform in question if you want to be sure.