Search code examples
c#unity-game-enginerenderinguielement

Hiding UI Element behind Other UI Elements


I'm having a problem with my UI Elements. I am spawning in enemies who have health bars which stay on top of them. The problem is, that if those health bars move through the position of other UI Elements i have (let's say the "Main Menu Button") they get rendered on top of that Element, not behind it.

It looks like this

I managed to spawn the healthbars in a different canvas so they don't interfere with the button itself by blocking raycasts but i can't manage to layer them behind the button (which changes position during gameplay too).

Thanks in advance!


Solution

  • If you have more than one canvas you can control the order of them using the sort order property in the canvas component. Sort order screenshot