Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

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

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

  1. rickblacker

    rickblacker

    Joined:
    May 1, 2014
    Posts:
    225
    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:
    6,157
    Its fine. Probably not the fastest if you scale it up but it's normal.
     
  3. rickblacker

    rickblacker

    Joined:
    May 1, 2014
    Posts:
    225
    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:
    4,440
    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,273
    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:
    347
    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. Fuzzy_Slippers

    Fuzzy_Slippers

    Joined:
    Dec 21, 2012
    Posts:
    460
    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:
    8,470
    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. Fuzzy_Slippers

    Fuzzy_Slippers

    Joined:
    Dec 21, 2012
    Posts:
    460
    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.