- Home /
Issues With Scene Transition
I am trying to switch from a main menu scene to a game scene. I have a splash screen setup to use during the transition however I run into problems. I have tried it different ways with different problems. First I tried this:
public void MountainCampButton() {
gameObject.SetActive(false);
splashScreen.GetComponent<SplashScreen>().SetLevel("Mountain Camp");
splashScreen.SetActive(true);
SceneManager.LoadSceneAsync("MountainCamp");
}
Thinking this should load the new scene and show it, then unload the old scene. This happens however right before the new scene is displayed the main menu is shown just for a fraction of a second. So I found that possibly the old scene is unloaded first before the new scene is loaded so I tried this:
void OnEnable() {
SceneManager.sceneLoaded += OnLevelFinishedLoading;
}
public void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode) {
switch (scene.name) {
case "MountainCamp":
SceneManager.sceneLoaded -= OnLevelFinishedLoading;
SceneManager.SetActiveScene(SceneManager.GetSceneByName("MountainCamp"));
SceneManager.UnloadSceneAsync("MainMenu");
break;
}
}
public void MountainCampButton() {
gameObject.SetActive(false);
splashScreen.GetComponent<SplashScreen>().SetLevel("Mountain Camp");
splashScreen.SetActive(true);
SceneManager.LoadSceneAsync("MountainCamp", LoadSceneMode.Additive);
}
Thinking I would be able to manually load and unload however this results in a warning in the load saying
Unloading the last loaded scene Assets/Levels/MainMenu.unity(build index: 0), is not supported. Please use SceneManager.LoadScene()/EditorSceneManager.OpenScene() to switch to another scene.
Which leaves my game still showing the main menu. Can anyone provide me with some assistance on making a smooth scene transition?
Answer by RobAnthem · Dec 29, 2016 at 08:10 PM
Honestly, I've never had to Delegate onto the sceneLoaded for unloading purposes, since your code finishes step by step, I suggest adding the Unload section just below the load section. Also, SetActiveScene isn't necessary since your unloading the old scene, it will force the player to the only active scene. I've never had a problem with scene transitions, one downside sometimes is that if your scene is small then adding a loading screen might appear more like a flicker, which sometimes leads to dragging out a load beyond what was needed.
Your answer
Follow this Question
Related Questions
AsyncOperation activating immediately even with async.allowSceneActivation = false; 0 Answers
SceneManager onActiveSceneChange Pause for a while before loading a new scene 0 Answers
Asynchronously Load a Scene, then switch to it on function call Unity 5.3 1 Answer
Android GAME Crashes After Splash Screen 2 Answers
WP8 - Changing splash screen from default causes app to crash after splash screen 0 Answers