- Home /
Loaded 2 async scenes: how to unload or remove 1 of them?
Basically I want to load 2 scenes, and then I want the player to be able to choose 1 of them to activate, using allowSceneActivation = true on one of the /AsyncOperation/, and I want to trash the other scene so I can load it at a later stage, or not load it all ever.
How do I do that?
I want something along those lines:
AsyncOperation async1;
AsyncOperation async2;
AsyncOperation playerChosenAsync;
void LoadSceneAsync(string sceneName1, string sceneName2){
AsyncOperation async1 = Application.LoadLevelAsync(sceneName1);
async1.allowSceneActivation = false;
AsyncOperation async2 = Application.LoadLevelAsync(sceneName2);
async2.allowSceneActivation = false;
}
void ActivateScene(AsyncOperation sceneToActivate){
sceneToActivate.allowSceneActivation = true;
}
void TrashScene(AsyncOperation sceneToTrash){
sceneToTrash.Trash(); // This method doesn't exist,
// but I want to unload/delete do something here,
// to release memory/CPU/whatevs.
}
IEnumerator Update() {
if(playerChosenSync == async1){
TrashScene(async2);
ActivateScene(async1);
playerChosenSync = null;
} else if(playerChosenSync == async2){
TrashScene(async1);
ActivateScene(async2);
playerChosenSync = null;
}
}
Same issue here, I need to load 2 scenes (win, lose) and show one of them depending on the player's result in each $$anonymous$$i game. But when I try to load both, one of them just stays in the inspector as "not loaded", even when I quit play mode, and it can't be removed, I have to close Unity and open it again.. This is happening in Unity 5.3.0 and 5.3.1
Yea it's currently impossible to load 2 scenes simultaneously (at least using the Unity API). You have to activate 1 scene before you start loading another scene. $$anonymous$$ind of weird, but that's how Unity has done it.
Then will just hope they fix that some day :/
Answer by lassade · Jan 11, 2016 at 02:32 PM
Give a look at this http://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.html i think is only for 5.3.
Im still working in a project made in 5.2 so i dont tried this functions yet.
If you are in the 5.2 and below i see some nice free plugins in the assets store dont remenber the name sadly.
But it works by placing every object in the scene inside a gameObject of the same name (and the name must be unique) so this way the script can just do:
GameObject.Destroy(GameObject.Find(sceneName))
Yeah I've also managed to do some workaround for the problem by just instantiating and destroying prefabs, but it will be much better if they allow multiple scene loading.
@lassade As said earlier, we have work arounds for this, but they are not very elegant. The new Scene$$anonymous$$anager does nothing to fix this (it handles the scenes the same way as before in terms of loading).
The Scene$$anonymous$$anager is just the new way of handling scenes in Unity 5.3, it still doesn't allow to load multiple scenes at the same time