Should I have multiple canvases in the same scene?

I am making a game which has an inventory system and a pause menu system and a UI displaying player hp,stats ,etc…

I was just wondering should I make a different canvas for each menu and activate one and disable the others when the user clicks on the main menu button or inventory button or should I have 1 canvas with 3 different panels and have them switch when the user interacts with the game?

1 Like

It seems I can’t delete the thread but anyways here is the answer, Just make sure not to use the update method and update the menus from the function in the video below, If you don’t you will have some glitches in your menu

2 Likes

In my experience, multiple canvases are not required for most situations. Better to have a single canvas and simply use multiple panels within that canvas for different screens / menus, then simply activate / deactivate them accordingly.

Also with the multi-scene management, a fair few titles are now having a UI dedicated scene which is simply added to the mix for your project.

Check out Unity’s UI sample on the Asset store for a great demonstration of this.

6 Likes

Although this might be the most way intuitive it is wrong. Just stating it for future reference as this thread appears at the top when searching for ‘multiple canvas’.

Having multiple canvas is more performant than having a single one full of panels. As a single change in just an element will make Unity re-draw and re-calculate everything (meshes, textures…) for that canvas.

Just check this link :https://unity3d.com/how-to/unity-ui-optimization-tips
It´s official and has a ton of other useful tips.
Everything in that blog is taken out of:

https://www.youtube.com/watch?v=_wxitgdx-UI

32 Likes

I found this thread by searching and let me tell you that simply adding more canvases is not the way to go. I decreased my performance a good deal by adding a canvas to every complex popup (as Unity suggests here… https://unity3d.com/how-to/unity-ui-optimization-tips#divide-up).
I’m now only using them on a scroll rect, and I’m not even sure if that helps in any way.
I also barely have any transform operations and certainly no animators (Dotween instead).
Having everything in 1 canvas makes my game so so so much more performant, it’s incredible.
So yeah, if you do
“You can also nest canvases, which allows designers to create large hierarchical UIs without having to think about where different things are onscreen across many canvases.”
like Unity suggests you’re setting yourself up for a world of pain.
Probably the best way is to use one main canvas and limit transform stuff. Carefully put them in the one eye-catcher spot and then use an extra canvas there.

Also layout groups aren’t bad. Maybe if you constantly change the content, but if you set it up once and then it’s static they’re no issue worth spending time on (like I did). Hint: On opening a dialog with layout stuff in it, disable the container → add new items → enable again.

Furthermore all my canvases have pixel perfect turned off. You can’t see a difference on mobile screens anyway.

1 Like

It would be interesting to see your setup in both cases.
For me there was a noticeable performance increase when I changed from 1 canvas to 2 or 3 canvases. Perhaps you were dividing into so many canvases that any performance gained by saving batches was countered by god-knows-what Unity task. Plus you mentioned you do not use animators etc, so your canvases should not be marked as dirty as frecuently as someone who does use them. And therefore Unity does not redraw your full canvas every Update step, negating any benefit that multiple canvases would provide in your particular case.
Or maybe something has changed internally in Unity in these past 3 years and I have not bothered to test out again everything, which, at the development rate Unity Tech. is carrying out is quite plausible.

Awesome. This was a fantastic read. Really helped me out! Thanks and thanks again. :smile:

1 Like

It’s not a good thing to create large hierarchies. The slight change in the child object will affect the whole chain. Expert says, Break any hierarchies unless they are not necessary

In fact, having a few canvases can be beneficial when it comes to draw order and top most important UI Object. Each to their own , but there is clearly nothing inherently wrong with using multiple canvases , or unity would have just made it so canvases were a single entity to which all ui falls under as a child within a single object.

1 Like

The real answer is: It depends.
It can be slower, it can be faster, but it’s not good general advice to just say “Use multiple canvases”.

As this is currently first result in Google search, I want to add that though you can have multiple canvases in a scene, only one of them will receive input, from what I’ve tested.

The video embed looks like it somehow broke but based on the date I suspect it was this talk:

UI optimization part starts @ 23:49

https://www.youtube.com/watch?v=_wxitgdx-UI

Yes, it was that one :slight_smile: