Reloading a scene causes extra unloaded scenes. How do I fix this?

SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);

This is the code I am using to reload the scene. Every time I exit the game mode, I see 2-5 unloaded scenes and 1 is loading scene that is a pain to get rid of. How do I stop these from appearing? I have the scene in the build settings

The code you posted above seems reasonable enough to reload, as long as you only have a single scene loaded.

Are you saying that when you terminate back to edit mode there are bunch of your other scenes open that were NOT there before, and that they are present in the editor in an unloaded state? I can’t imagine this is caused by the above script, unless you put it somewhere weird like OnDestroy() or OnDisable() or in some other edge-called location such as the “On scene loaded” callback or something…

I figured it out. It was because I put it in OnDestroy. Thanks though, now the solution is here.

1 Like