Positioning ui elements - translation vs left/right?

I want to position some elements using x,y coordinates.
Is there any performance advantage to use position: absolute with left/right versus translation?
Does DynamicTransform usage hint takes into account translation only or absolute position too?

DynamicTransform also works with absolute positions. However, changing the left/right values will require a layout pass. Changing the transform is guaranteed to not affect the layout, so it will perform better.

1 Like

Thank you! So if I have icon that I want to set some (x,y) coords, but I want it to be pivoted in the center, not top left corner (black square is icon):


then I need to create container with DynamicTransform to set translation, plus the actual icon visual element as child, but without dynamic transform and translated by -50% -50%, correct?

Additional question, is layout pass expansive if there is only one element, or all of them are moved anyway?
In my case there are multiple UIDocuments + my script attached to various gameobjects. My script transforms world position to panel position and updates icon position every frame.
I am not sure how layout is recalculated in this case - is every document separated from each other when it comes to layout and can’t trigger pass to others?

Rotation and scale transforms are applied relative to the transform-origin of the element, which is the center of the element by default. So it shouldn’t be necessary to create an intermediate parent.

If your elements are in position: absolute, the layout should be cheap (but not entirely free if my memory serves). Setting you elements in absolute position and modifying the transform is probably the most efficient way to do it.

1 Like


I want to get behaviour on the left.
When I set transform position to (0,0) its moved to corner, but the origin is in left top corner (right example), so I need to translate it by 50%, however I need additional element inside, because translation is already used to set “absolute” position on screen. Am I missing something?

You are correct, for the translation, you’ll need an intermediate parent to get the desired location.

2 Likes