- Home /
Can someone explain this exception? ArgumentException: SceneManager.SetActiveScene failed; invalid scene
I am loading a scene from an asset bundle. Everything was working fine, but then I switched to loading the scene additively and now I'm getting a strange exception when I try to set the scene active.
Here's my code:
IEnumerator LoadSceneCoroutine(string pSceneName){
yield return SceneManager.LoadSceneAsync(pSceneName,LoadSceneMode.Additive);
Scene chapterScene = SceneManager.GetSceneByName(pSceneName);
SceneManager.SetActiveScene(chapterScene);
}
I get an exception:
ArgumentException: SceneManager.SetActiveScene failed; invalid scene
What does this mean? What about my scene is invalid? Are there certain requirements that must be met for a scene to be set active? A google search for this error returns almost no results and the documentation is not helpful either so I'm stumped. Please help! Thanks.
Answer by cabbyU · Nov 22, 2018 at 10:58 PM
Okay, I figured it out. It turns out I was actually passing a scene path to that function, not a scene name as the name of the parameter suggests. Thus, I needed to use GetSceneByPath instead of GetSceneByName. GetSceneByName was, in fact, returning an invalid scene that didn't exist.
Answer by carterdawson · Nov 22, 2018 at 11:01 PM
I'm guessing that although the LoadSceneAsync function has completed, the scene is not fully loaded.
What happens when you try this in the debugger. Any difference?
What about just running the LoadSceneAsync in its on Coroutine, and then setting the active scene in the OnSceneLoaded callback of SceneManager? Does that change anything?
Your answer
Follow this Question
Related Questions
Why does a scene loaded from an Asset Bundle returns empty string when getting its name? 0 Answers
'Resource file has already been unloaded' error when exiting application in Editor 1 Answer
Scene assets not bundled in asset bundle 0 Answers
How to load a scene from an asset bundle in unity 5? 1 Answer
Asset Bundle starts loaded 0 Answers