Documentation

Unity Engine

Download Unity

Unity Engine

Code lifecycle execution order reference

Understand the execution order of Unity's code reload process, including domain and scene reload, and how it affects the lifecycle of your scripts.
Read time 1 minuteLast updated 2 days ago

Unity's code lifecycle APIs allow your code to hook into key phases of the code loading, unloading, and reloading process. This section shows where these callbacks fit into the overall execution order of the code reload process, and how they relate to other events in the Unity Editor and Player.

Code reload

The following diagram shows code reload triggered by a change to scripts and includes the active code lifecycle scopes during each phase of the reload:

The execution order of code lifecycle callbacks and other related events during code reload triggered by script changes in the Editor. The left column shows the sequence for code reload triggered while in Edit mode and the right column shows the sequence for code reload triggered while in Play mode. Includes the lifecycle scopes active during each phase of the sequence.

Startup and shutdown

The following diagram illustrates the startup and shutdown process in the Editor and Player:

The execution order of code lifecycle callbacks and other related events during startup and shutdown of the Editor and Player. The left column shows the startup sequence for the Editor and Player. The right column shows the shutdown sequence for the Editor and Player. Includes the lifecycle scopes active during each phase of the sequence.

Enter and exit Play mode

The following diagram illustrates entering and exiting Play mode in the Editor. While Play mode is an Editor-specific concept, the diagram includes sections of the sequence that are shared by the Player on startup and shutdown:

The execution order of code lifecycle callbacks and other related events when entering and exiting Play mode. The left column shows the sequence on entering Play mode. The right column shows the sequence on exiting Play mode. Includes the lifecycle scopes active during each phase of the sequence.

For a detailed view of the execution order when entering Play mode without code and scene reload, refer to Domain and scene reload execution order reference.

Additional resources