localPosition.y returns wrong value

Hello,

a UI image element that has been anchored to the top of the parent and with stretched width and also with “-150 Pos Y” will not return “-150” when calling theObj.localPosition.y. Instead it will return a position based on the viewports height. What is up with the value? Why will it not return “-150”?!

42167-see.png

Don’t use localPosition for UI elements, it has different values than the ones you see in the Rect Transform depending on anchors and pivots, that’s why the inspector doesn’t show you the local position directly.

If you want to get the value of “Pos Y” you see in the inspector use theObj.anchoredPosition.y