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
.
To configure script execution order, go to: Edit > Project Settings, and then select the Script Execution Order category.
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.
EngineBehaviour
script configured to execute before a SteeringBehaviour
script, both would update on one scene before they updated on the next one.[RuntimeInitializeOnLoadMethod]
attribute.OnDisable
and OnDestroy
functions.