Search Unity

Should I have multiple canvases in the same scene?

Discussion in 'UGUI & TextMesh Pro' started by la3eb, Feb 11, 2017.

  1. la3eb

    la3eb

    Joined:
    Feb 11, 2017
    Posts:
    12
    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?
     
    anycolourulike likes this.
  2. la3eb

    la3eb

    Joined:
    Feb 11, 2017
    Posts:
    12
    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
     
    Last edited: Feb 11, 2017
    aetherfang_unity likes this.
  3. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    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.
     
  4. jc-drile77

    jc-drile77

    Joined:
    Jul 1, 2014
    Posts:
    230
    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:
     
    Last edited: Sep 1, 2018
  5. drallcom3

    drallcom3

    Joined:
    Feb 12, 2017
    Posts:
    165
    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.
     
    Last edited: Mar 6, 2020
    will_unity731 likes this.
  6. jc-drile77

    jc-drile77

    Joined:
    Jul 1, 2014
    Posts:
    230
    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.
     
  7. Kokowolo

    Kokowolo

    Joined:
    Mar 26, 2020
    Posts:
    60
    Awesome. This was a fantastic read. Really helped me out! Thanks and thanks again. :D
     
    will_unity731 likes this.
  8. lasdoo5

    lasdoo5

    Joined:
    May 18, 2018
    Posts:
    16
    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
     
  9. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    657
    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.
     
    pioj likes this.
  10. drallcom3

    drallcom3

    Joined:
    Feb 12, 2017
    Posts:
    165
    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".
     
  11. Krosenut

    Krosenut

    Joined:
    Jun 1, 2023
    Posts:
    20
    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.
     
  12. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    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
     
  13. jc-drile77

    jc-drile77

    Joined:
    Jul 1, 2014
    Posts:
    230
    Yes, it was that one :)