Preload Scene

  10. Advanced No Comments

The Preload Scene (also known as the Boostrap Scene) is a technique where you always launch your game from the same scene. This enables you, among other things, to place important global services into this scene, and ensure that they are always loaded before any other scene objects in the game.

One big pain point that using this pattern can often cause is making Editor testing much more difficult – if it is vital that your Preload scene is always the first one to be loaded, then you’ll no longer be able to enter Play Mode from any other scenes to quickly test them…

Init(args) can get rid of this pain point. All you have to do is:

  1. Make sure your preload scene is the first scene in the Scene List of your active Build Profile.
  2. Register at least one global service from the preload scene using the [Service] attribute, set LoadScene to your preload scene, and do not set LazyInit nor LoadAsync to true.

[Service(LoadScene = "PreloadScene")]
class UIManager : MonoBehaviour { }

If the preload scene is not open when you enter Play Mode, Init(args) will automatically load it additively, and makes sure that objects in that scene are initialized before objects in any other scenes.

Leave a Reply

Your email address will not be published. Required fields are marked *