ina
1
When should we use the Canvas object multiple times in UGUI
Kiwasi
2
Sure. Here is my reasoning
Every world space UI element should be on its own canvas.
Every camera can have its own camera space canvas.
Even in screen space the workflow can be much better with separate canvases for separate menus. Overhead of maintaining a disabled canvas is almost non existent.
Edit: If you are using a lot of canvases that are for display purposes only, remove the GraphicsRaycaster component. This component checks for input each frame, and is not really needed for things like health bars or floating number.
I am with @BoredMorman. I have learned that it in fact is recommended to use multiple canvases to improve performance (of course this would depend on what kind of a setup and what scenario) and not to mention easy to organize.
Unity updates ALL its elements in a canvas regardless of how many items you really changed. E.g. let’s say you change one parameter, like a player score text, but unity updates the whole hierarchy under that canvas) it updates every the elements of that canvas regardless of what was changed. Now imagine changing something like player health bar, which usually happens every frame. If you have all your items in one canvas, every frame Unity will go one by one and update all your items.
Well, Ian Dundore from Unity explains this in much more depth and way better than I ever can:
I wrote a game with enemies where each enemy has its own canvas (life bar). Indeed the canvas was a part of the prefab. I did not observe a significant drop in performance. I have to state that there were no more than 20 enimies present at the same time…
So i think it’s dependent of the purpose. As long as you use only a few canvases, i don’t think that you should limit yourself to only one. The drawbacks of only one canvas managing all game tasks (menu, health bars, hit marker, whatever) lead to more dependency in your project, to more confusion, to less maintainability, aka to code that tends to get a mess.
Bwhang
4
I have one Canvas for most of my gui elements, and a second canvas for extra gui buttons for android version: Pause, Left, Right, Jump.
I destroy the android gui if the version isn’t android.
In my case, I’m using a Color Picker prefab that only works on Canvases in Overlay mode, and I’m using it to affect a Spine Skeleton Animation, which does not work in Overlay mode. So I stack one Camera Render canvas for the Skeleton Animation on top of an Overlay Render canvas for the Color Picker and other UI, and voila.
Well I bumped into this issue, when you want to hide 3d game object with the ui buttons and for that multiple canvas are needed, unless you don’t mind mapping all those buttons to the variables.