Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to keep UI overlay across multiple canvases in a scene?

Discussion in 'Game Design' started by philipsmith290, Dec 15, 2020.

  1. philipsmith290

    philipsmith290

    Joined:
    Nov 30, 2020
    Posts:
    11
    Hi,

    how can I build a UI that persists across multiple canvases? That is if I change to another canvas on the scene, the UI remains.
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    What you're asking doesn't really make sense to me. If you have some UI that should "persist" as other canvases change, then just place that stuff is its own canvas. You can have multiple active canvases at the same time, with the Sort Order controlling which one is on top.
     
    angrypenguin and JoeStrout like this.
  3. philipsmith290

    philipsmith290

    Joined:
    Nov 30, 2020
    Posts:
    11
    So how would I approach this then? I've got two canvases, each has a button that changes the canvas, but I lose the elements when I swap canvases.

    How can I make UI elements that persist?
     
  4. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,514
    This could mean lots of different things. What specifically is that button doing?

    You need buttons inside one Canvas which activate or deactivate other Canvases.
     
  5. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    438
    Are you using the "highest" type of UI layer? That is, the overlay mode? This one sort of lives in its own domain and is last displayed so as to behave like a HUD. You might want to try components that allow you to order things according to layers.
    It sounds like you want elements from canvas #1 to be transferred to canvas #2, perhaps, I guess, with a drag and drop menu. Maybe you're doing a RPG inventory and you display a popup that contains items and you'd like to drag them into the main inventory "window"? This could be done within a single canvas anyway.
    Otherwise, you can try reparenting game objects.
     
  6. philipsmith290

    philipsmith290

    Joined:
    Nov 30, 2020
    Posts:
    11
    Sorry - What I am trying to achieve is -

    basically a simple clicker game, that has the main screen with the clicker stuff and then another scene (canvas?) which is like a buy menu.

    All of these screens would have would have a left hand navigation, similar to this -
    I want to be able to reuse those components no matter which screen is selected, but not unload or lose action in the main screen/canvas when in the second screen.

    How would I go about having multiple scenes/canvas that have an overlay that isn't lost when changing between the two of them? I don't want all elements transferred just the "menu" elements, effectively.

    Basically - how would I go about trying to do this -

     
    Last edited: Dec 17, 2020
  7. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,580
    You can keep your UI as separate scene, which is on the top.
    Then load / unload your game level scenes.
     
    TebogoWesi likes this.
  8. philipsmith290

    philipsmith290

    Joined:
    Nov 30, 2020
    Posts:
    11
    So would that be two different scene objects? Is there any documentaiton or video on how this could be done, or someone able to show me an example?
     
  9. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    438
    Load your scene in additive mode and keep an eye on deletion if unloaded too.
     
  10. philipsmith290

    philipsmith290

    Joined:
    Nov 30, 2020
    Posts:
    11
    Would deleting/onloading cause the actions in that scene to stop? For instance - if clicking and going gold per second, I'd want thtat to continue.
     
  11. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,580
    Will not, if you design scene management righ.
    Mind, you can have more than active scene.
    One for UI, one for core mechanics another one scene1 etc.
     
  12. philipsmith290

    philipsmith290

    Joined:
    Nov 30, 2020
    Posts:
    11
    Can you please link me an example or appropriate documentation for this?
     
  13. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847