UI Prefab draw-order

I am having a small problem with the UI draw order:

I know that UI elements are drawn according to the hierarchy, from top to bottpm. Usually that is quite usefull, but currently it creates a problem for me that doesn’t seem to be solveable easily.

I have a collection of UI-elements (>20), which are created during runtime. These are instances of a prefab, which consists of an Image and a Text GameObject. The Text should always be drawn on top of the Image (which is simple), but it should also be drawn on top of the Image of the other instances’ Images (which is a problem). I could rip apart my prefab and have separate objects for the Image and the text, each in a separate hierarchy, but I find that a bit stupid and backwards. Is there a better solution?


I have two ideas, i haven’t tested any of them.

  1. Change the z parameter of the number 4 item (i’m sure that it works, but i can’t launch Unity right now to check)
  2. Duplicate and tweak the UI Shader so that it renders “above all”. Apply the new shader to the numbers only

After adding the element, update text hierarachy position to last using SetAsLastSibling ().