Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to turn off scene without unloading it in game?

Discussion in 'Scripting' started by FeastSC2, Feb 13, 2020.

  1. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    How to turn off scene without unloading it in game?

    I would like to do after a scene is loaded.
     
    lucbloom likes this.
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You can set all the scene's GameObjects to inactive. Then make them active when you want to use the scene.
     
    lucbloom likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,517
    Easiest is to organize the scene so it all shares a common root game Object. This might not be possible, but then you just
    .SetActive(false)
    that object and you might be done, assuming everybody handles their lifecycles properly (i.e., use
    OnEnable()/OnDisable()
    properly, etc.).

    Alternately you can iterate all GameObjects and see what scene they belong to, keeping only the
    transform.root
    objects, then spin and set those all inactive and back active when you want them back. Same caveats as above apply.
     
    Joe-Censored likes this.
  4. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    Yes, I expected that would be the only way. Ok, thanks.

    I thought there might have been a way to do it just like in the editor does the "scene (not loaded)".
    upload_2020-2-13_19-39-20.png
     
    boddle likes this.