Recently, I noticed a weird behavior on my loading screen. For some strange reason, it’s duplicating the scene to load (it’s loading the same scene twice). I don’t really understand why this is happening.
This is how my loading process works:
The loading screen itself is isolated in its own scene. I use an event system (Game Events approach) to call the loading screen when I need it.
My game has a boot scene. This scene only contains a script that solves some future issues of the session and loads the loading screen.
When a new scene is loaded, the other one (the scene in which the loading screen was called) is unloaded with this code:
Application.backgroundLoadingPriority = ThreadPriority.Normal;
loadingOperation = SceneManager.LoadSceneAsync(levelName, LoadSceneMode.Additive);
int _sceneCount = SceneManager.sceneCount;
for (int i = 0; i < _sceneCount; i++)
{
Scene scene = SceneManager.GetSceneAt(i);
if (scene.name != "LoadingScreen")
{
SceneManager.UnloadSceneAsync(scene);
yield return null;
}
}
Next, we’ll wait until the loading is done:
while (!loadingOperation.isDone)
{
yield return null;
}
After that, I set the newly loaded scene as the active scene:
SceneManager.SetActiveScene(SceneManager.GetSceneByName(levelName));
And I end the coroutine with a yield return break;
Now, once the boot scene is unloaded, the loading screen take us to the main menu, where the user can start the game and do other things. To call the loading screen (in other scenes after boot), I use a Loading Screen Caller. It literally only calls the loading screen to load a new scene:
[SerializeField] private StringDataType setString;
[SerializeField] private GameEvent eventToCall;
public void LoadNewLevel(string levelName) {
setString.SetStringValue(levelName);
eventToCall.Raise();
}
Since the Loading Screen scene is already loaded, it can “hear” that the event was raised, and therefore, load a new scene.
But when I load the next scene from the main menu, the scene in question duplicates itself and the scene manager load both of them. It’s weird, since I use the same logic for loading from the boot screen, and that doesn’t happen from there.
This is strange, since this doesn’t happen on other projects, and they use pretty much the same logic.


