Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

load multiple scenes at once and switch without destroying

Discussion in 'Getting Started' started by knobby67, Jun 4, 2016.

  1. knobby67

    knobby67

    Joined:
    Aug 30, 2015
    Posts:
    331
    Hi All,
    new to Unity and have asked a few questions related to this in the past couple of weeks. But now I'm finally test programming and watching tutorial videos I'm a bit confused.
    So my question is, as per title, can I load multiple scenes "at once" and then select scene without destroying others. My layout is


    central Hub scene
    |
    World 1 hub world 2 hub
    | |
    mini scene 1 mini scene 1
    mini scene 2 mini scene 2
    mini scene 3 mini scene 3

    Game loads Hub scene, one select world 1 , 2 ... is loaded instantly after load it then async loads all three mini scenes, player selects mini game, plays mini game, returns to world hub, then can select any mini game again.
    So I only load mini scenes once at entry to the world hub. On leaving world hub, world and mini games are destroyed, player returns to central hub and selects a world, and repeat above.

    I though I could use async load, but on reading tutorials forums, I'm now confused, some people are saying async is just for loading bars between scene switches, some are saying when switched you destroy former scene, etc. I think my confusion is caused by so many answers on the net for older versions of Unity.

    So basically is it possible to load multiple scenes and switch without destroying the other scenes. If so can anyone point me to a tutorial. Thanks
     
  2. knobby67

    knobby67

    Joined:
    Aug 30, 2015
    Posts:
    331
    Should add I've read through tutorial http://www.alanzucconi.com/2016/03/23/scene-management-unity-5/
    Which seems to indicate you can only have one loaded at a time

    "Ghost scenes.
    Every time you load a new level with SceneManager.LoadScene, Unity flushes all the scenes that have been previously loaded. Only game objects that invoked DontDestroyOnLoad (documentation) survive the process."
     
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,187
    That's not necessarily true. You control this via the optional 'mode' parameter (see the docs). If you set this to LoadSceneMode.Additive, then the new scene objects are added to the current scene.

    So you could have each of your mini-scenes set up with all objects inside some root object whose name you know (e.g. "MiniScene1", "MiniScene2", etc.). That object should be initially inactive. Then you can load them all up with LoadSceneMode.Additive, and call SetActive to switch quickly from one to another.

    There's also SceneManager.SetActiveScene, but it is essentially undocumented, and it's not at all clear to me what that actually does.
     
  4. knobby67

    knobby67

    Joined:
    Aug 30, 2015
    Posts:
    331
    Thanks for the advise :) I,ve been looking at scenemanager, but like you I can find little advise on it, even when I google it seems to be people writing their own scene manager. The only tutorial I could find was the one in the post about. But He / She gives up before the show how to use the manager to load multiple scenes :s
     
  5. Purplepigfarm

    Purplepigfarm

    Joined:
    Aug 10, 2016
    Posts:
    25
  6. BanzBowinkel

    BanzBowinkel

    Joined:
    Jun 17, 2015
    Posts:
    6
    yinyinh likes this.
  7. clang2

    clang2

    Joined:
    Jan 27, 2018
    Posts:
    6
    Regarding what SetActiveScene does, I also found this thread (note response #14):
    https://forum.unity.com/threads/scenemanager-setactivescene-does-not-work-solved-workarounds.381705/

    The active scene becomes the basis for global scene settings as well as the target for instantiated objects.

    Just don't forget that a scene loaded additively means all scenes are still active, even after using SetActiveScene to switch views. So if you have a main scene and then additively load a mini scene like a side game, the controllers in both scenes will be active.
     
    Joe-Censored likes this.