Manual: Script Execution Order reference (original) (raw)
Quality settings tab reference
Use the Script Execution Order settings to specify the relative execution order of different MonoBehaviour script components in your project. The execution order between different scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary in the project is different from and doesn’t change the order of execution for event functions within each individual script. Unity always calls Awake before the first Update for each script, but you can configure script execution order to ensure that Awake
for one script is always called before Awake
for another. For example, if you have two scripts, EngineBehaviour
and SteeringBehaviour
, you can set the script execution order so that EngineBehaviour
always updates before SteeringBehaviour
.
Configuring execution order
To configure script execution order, go to: Edit > Project Settings, and then select the Script Execution Order category.
The Script Execution Order section of the Project Settings window displays a list of script classes and their currently configured execution order values.
- Use the plus (+) button to add scripts to the list. Use the minus (-) button on a list item to remove it from the list.
- To specify the execution order, drag items in the list into the desired position or edit the integer values of a script in the list.
The integer values assigned to each script don’t represent any quantity but define each script’s execution order relative to the others. Unity executes scripts in order from lowest first to highest last, for example: –200, –100, –50, 50, 100, 200. The Editor stores these values in the script metadata files. You can leave gaps between the values to help avoid unnecessary file changes when you add or move other scripts in the list.
Unity executes any scripts not in the list during the Default Time slot, which occurs after any scripts with negative values and before any scripts with positive values.
Note: You can specify the script execution order from code rather than configuring it in the Editor by applying the [DefaultExecutionOrder]
attribute to your MonoBehaviour-derived classes. For more information, refer to the [DefaultExecutionOrder] API reference.
Important considerations and limitations
- If you assign multiple instances of the same scripts to different GameObjects, all instances of a script with a lower execution order value are executed before any instances of a script with a higher execution order value, regardless of which GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary they’re attached to. - When multiple scenesA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary are loaded additively, the configured script execution order is applied in full for one scene at a time rather than partially across scenes. In the previously cited example of anEngineBehaviour
script configured to execute before aSteeringBehaviour
script, both would update on one scene before they updated on the next one. - When multiple scripts have either the same configured execution order or the default execution order, the order of execution between them is not deterministic. While the order might appear consistent during testing, you should never rely on this behavior, because it isn’t guaranteed across builds, machines, or Unity versions. For more information, refer to Order of execution for event functions.
- The execution order specified in the Script Execution Order settings window doesn’t affect:
- The order of functions marked with the [RuntimeInitializeOnLoadMethod] attribute.
- OnDisable and OnDestroy functions.
Additional resources
Quality settings tab reference