Question by
MisschienWelChristiaan · Jan 30, 2017 at 11:32 AM ·
load scene
Unload all scenes except one
So i have 10 scenes for example, 1 is GUI, 2nd is City, 3rd is forest, 4th is Castle, 5th is Lake etc.
I want to move from place to place but keep GUI loaded as it holds the connection script. The GUI is where it starts and the places are loaded like this : SceneManager.LoadSceneAsync ("EXAMPLE", LoadSceneMode.Additive);
How can i do this?
Comment
Answer by skauth · Oct 25, 2017 at 02:45 AM
void UnloadAllScenesExcept(string sceneName) {
int c = SceneManager.sceneCount;
for (int i = 0; i < c; i++) {
Scene scene = SceneManager.GetSceneAt (i);
print (scene.name);
if (scene.name != sceneName) {
SceneManager.UnloadSceneAsync (scene);
}
}
}
I do this at the Start() of GameManager, but with sceneName hardcoded to "Main", so that I can leave my scenes loaded in the editor instead of manually unloading before I hit play.
Sorry it's a late answer. Hopefully you already found your solution, and this helps someone else in the future.
Old post, but just found it and it worked like a champ for me. Thanks!