Load a scene "behind" the current scene.

I have a couple of scenes in my game which just contain dialog which reveals the next part of the story. At the bottom of the screen is a continue button to move on to the next section of the game.

What I’d like to do is have the next level (next scene) loading while the player reads through the story, and have the continue button not enable until the loading is complete. Currently the “Continue” button just loads the next scene, so there’s a pause during which the player has nothing to do. Makes sense to be loading WHILE they’re reading.

I’ve been looking into LoadLevelAsync, but I’m not sure that’s the right thing. It seems like when that finishes loading, it’s just going to switch straight to the next scene?

Is there a way to load the background scene and monitor progress. Then, once progress is 100%, enable my “Continue” button, which - when clicked - then switches to the new scene that was background loaded?

LoadLevelAsync() is the right API for this. It returns an object you can use to track progress and decide when to enable your Continue button.

How do you do the actual “switch” to the background loaded scene though? i.e. code attached to the “Continue” button.

The action jumps to the new scene as soon as it is loaded, so LoadLevelAsync isn’t a good way to preload a new level while the current level is still playing. Unfortunately, there isn’t a PreloadLevelAsync or anything like that but there are couple of things you can do to spread the loading time out during the gameplay.

One simple approach is to use LoadLevelAdditiveAsync. This actually combines the loaded scene into the current one and keeps them both playing. If you divide the scene into different areas corresponding to the different game levels, then you can load a new scene in the background and move over to it when necessary. It’s not completely straightforward, since the code in the new scene starts executing as soon as it is loaded so you will probably need to start with some of the scripts deactivated.

Another, more flexible approach that you can use with Unity Pro is to load the scenes as usual but put some of the larger assets into asset bundles. The asset bundles can be loaded asynchronously during gameplay, so in your case, you could load the larger assets for the next scene while the user is reading the story text.

1 Like

Thanks heaps for the info - will play around with that stuff and see what I can come up with. I might add this to the wishlist or something. I’ve seen it done quite a lot in modern games (usually during things like “Mission Briefings” etc, so it would be neat to have it built into Unity.

I know this is an old thread but I figured since this is the first thing to pop up when googling how to load a scene in the background that a current solution should be posted. SceneManager.LoadLevelAsync() returns an instance of AsyncOperation which has the member boolean allowSceneActivation. Simply set that to false as soon as you get the instance of AsyncOperation. Once you are ready to show the level, just set it to true. Keep in mind that scenes have to be activated in the order they’re loaded, and if you loose the instance of AsyncOperation before you set allowSceneActivation to true you will be unable to load any further scenes until restarting unity. Best of luck!

Also I forgot to mention that the progress member only goes from 0 to 0.9 and only hits 1 once the scene is activated and the isDone member also won’t be true until the scene is activated, so when checking for completion check that progress == 0.9

The biggest problem for me when loading a scene in background in general is, that it consumes a lot of performance and
moving objects start to jitter or even interrupt movement until the scene is opened.

You can use

to give loading a lower priority. Loading will take longer, but with lower performance hit.