Programmatically moving UI elements in front of others

I have a fairly complex UI built of Unity GUI. It has health / mana bars on the screen that are instantiated dynamically from a prefab. In the same Canvas there is a hidden panel that is supposed to be in front of everything else when it is displayed. However, when it is displayed the health / mana bars appear in front of it. I cannot move the hidden panel to the bottom of the Canvas elements in the tree view because the elements that are appearing in front of the hidden panel aren’t generated at design time.

Is there a way for me to further change the layering order of UI elements besides just which elements are farther down in the hierarchy? Or is there a way to programmatically change how far down in the hierarchy a particular element is?

Transform has methods SetAsFirstSibling(), SetAsLastSibling(), and SetSiblingIndex() that can be used to change the tree order at runtime.

1 Like

Ah, thanks. I was looking at intellisense for MoveToFront or BringForward but didn’t think to look for the others.