Distribute scene objects' initialization process (i.e. Awake()
calls) evenly throughout multiple frames, easing scene loading processes.
- Put
ObjectsPreWarmer.cs
on a scene-level GameObject component. - Select the GameObject, and press the lock icon on the inspector to lock the inspector view to the GameObject.
- Use shift-click to select multiple objects that you wish to be prewarmed into the field
Pre Warm Objects
. - (Optional) You can change wheter you want to pre-warm during awake, the interval between awake processes (default interval is
Time.deltaTime
), and how many GameObjects you wish to prewarm during each operation. - Enter Play Mode to see the pre-warm results.
- When a scene with a lot of GameObjects are loaded, the initialization calls can sometimes slow down the game at the beginning.
- With
ObjectsPreWarmer
, you can even the initialization calls across multiple frames, optimizing scene loading processes. - Make sure this script runs first in each scene by changing the Script Execution Order, this is done with
[DefaultExecutionOrder(-15)]
in the script.