How to update a RectTransform's AnchoredPosition when its pivot is changed

Asking this here since I cannot find a forum related to UI that is alive.

I am changing the pivot of a RectTransform at runtime and want to take the new anchoredPosition that results from this change and use it for tweening.

However the value I get from panel.anchoredPosition.y is still the old anchoredpos. I tried waiting for 1-2 frames before asking for the value, I tried panel.ForceUpdateRectTransforms(), no result.

I would simply author a separate invisible GameObject that you use as the pivot.

The reason is that manipulating RectTransforms is almost always a complicated disaster.

For instance it is some 15 lines of code just to set the anchors to the outside of the RectTransform.

http://forum.unity3d.com/threads/script-simple-script-that-automatically-adjust-anchor-to-gui-object-size-rect-transform.269690/

1 Like

because changing the pivot doesnt change the anchored position

it does in the editor but that is because the editor is wacky

what you need is a formula that copies the wacky behaviour of the unity editor

with that being said when the moderators find this thread they are gonna send u back to the shadow realm

1 Like

Kurt, I did it the way you described and it worked out. Thanks!

1 Like