Search Unity

Architecturally, is it normal to have multiple canvas in your scene?

Discussion in 'UGUI & TextMesh Pro' started by rickblacker, Jul 13, 2018.

  1. rickblacker

    rickblacker

    Joined:
    May 1, 2014
    Posts:
    266
    Without going into a lot of boring detail. Is it acceptable to have multiple Canvas in your scene? The biggest reason I'm wanting multiple is because each thing I want on the canvas does a different thing. Like, displaying images, fading alpha, playing video. Each needs the ability to be displayed and hidden.
     
    Last edited: Jul 13, 2018
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,498
    Its fine. Probably not the fastest if you scale it up but it's normal.
     
  3. rickblacker

    rickblacker

    Joined:
    May 1, 2014
    Posts:
    266
    Speed in this particular app is not a concern. Ok, cool. I just wanted to make sure I wasn't attempting to break some kind of "best practice".
     
  4. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,682
    IIRC, any time you make a change to something on a canvas, it redraws the whole canvas. So you do want to separate out functions that update independently.
     
    dadude123 likes this.
  5. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    I have a canvas for each GUI 'screen', so at most there's usually only 2 canvases shown (GUI screens crossfade)
     
  6. eatsleepindie

    eatsleepindie

    Joined:
    Aug 3, 2012
    Posts:
    355
    You want to group items in canvases so that the group is getting updated as a whole whenever possible without updating anything else. For instance, if your resource calculations run once per second in your RTS, you want to update your header's resource counts all at once and also have those separate from a canvas that updates when the player interacts with it. Also make sure you turn off raycasting for any UI elements that don't require it, which can degrade performance, especially on mobile.
     
    TonyLi and hopeful like this.
  7. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    Yeah I believe you should actually have a bunch of canvases. My current game has like 6. Unity doesn't make these kinds of best practices very obvious.
     
    hopeful likes this.
  8. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,688
    This is a good resource: A guide to optimizing Unity UI

    In particular, this section: Fill-rate, Canvases, and Input.

    This isn't just when you activate or deactivate a GameObject or change the content of a Text element, but also every single frame if it has an active Animator. The guide has tips for avoiding these issues, such as using a tween script instead of Animator, and disabling canvases efficiently.
     
    hopeful likes this.
  9. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    It seems like then you do want to split up all your elements from the commonly updated ones. Like canvases split among HUD (health bars and such) Top Elements (cursors, tooltips) Frequently Changed Menus (character screens, inventories) Irregularly Changed Menus (book screen, death screen, map) and Static Menus (main menu, save/load menu)

    That way every time you change cursor you aren't rebuilding a very complicated hierarchy like a main menu. The penalty of a few extra draw calls seems worth it.