Code and scene reload execution order reference
Understand the work Unity performs during code and scene reload and what's skipped when they're disabled.
阅读时间1 分钟最后更新于 5 天前
From a high-level perspective, entering Play mode consists of the following main stages:
- Backup current scenes. This only happens when the Scene has been modified. Allows Unity to revert the Scenes when exiting Play mode to the state they were in before Play mode started.
- Code reload. If you have configured it to perform code reload on entering Play mode, the Editor reloads code to reset the scripting state.
- Scene reload. Resets the Scene state, by reloading the Scene.
- Update scene. This happens twice; once without rendering, and once with rendering.
The combined tasks of code reload and scene reload reset the scripting state and simulate the startup behavior of your application as it would run in the Player. The following diagram provides detailed information about the exact steps Unity performs during scene and code reload, and which steps it skips when they're turned off. Blue indicates the events Unity skips when code reload is off (which it is by default), and green indicates the events Unity skips when scene reload is off.
Event functions in the MonoBehaviour script lifecycle. Event functions skipped when code reload is off are highlighted blue. Event functions skipped when scene reload is off are highlighted green.