I think there is no way to manage depth at runtime except for chaning sorting order at Canvas.
so I make each ui composition attached a canvas for it and also make it into prefab for instantiating as I want.
is it ok to use canvas like it?
I think there is no way to manage depth at runtime except for chaning sorting order at Canvas.
so I make each ui composition attached a canvas for it and also make it into prefab for instantiating as I want.
is it ok to use canvas like it?
The canvas is ONE way of sorting your UI. The other is, to manipulate the order of the objects in your Hierarchy window (use Transform.SetSiblingIndex from scripts, e.g. when creating new UI elements on the fly). The canvas gets rendered from top to bottom, so any object in the hierarchy window that comes after any other will be drawn in front.
In your example screenshot, “Panel” will be behind “Image” and “Text”. While “Image” will be behind “Text”. “Text” is in the front, because its the one in the bottom of the Hierarchy view. If you would want, say… “Text” to be behind “Image”, you need to move it above “Image”.
There is another impact of having a seperate canvas to consider: Each canvas will be a separate draw call to the graphics card. But on the other hand, a canvas only needs to be rebuild its vertices if anything within this very canvas changes.
So when should you use which method?
Sorry, I'm late. I re-structed UIs not to use canvas many as you said and it seems to work well as I expected. Thank you for the tips!
– BigChoTrain
Hi, Why do you need to add multiple canvas to your UI? If what you want is create multiple menus and display one at a time; then this is not necessary. You can create each menu in a separate GameObject (not the canvas script attached) and just enable or disable the GameObject to display the required menu.
– anasiqbalThe reason why I did like above is a post I saw that saying managing depths at Runtime can be controlled by a canvas attached to each UI element.
– BigChoTrain