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.Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.