Menu
CoddyTech

The Lifecycle Order

Part of the Unity Scripting Basics section of Coddy's Unity journey. Lesson 58 of 67.

Unity calls a script's methods in a fixed order, from the moment its object appears to the moment it is destroyed:

  1. Awake(): once, when the object is loaded or spawned.
  2. OnEnable(): right after, and again every time the object is shown.
  3. Start(): once, before the script's first frame.
  4. FixedUpdate(): on the physics clock, 50 times a second by default, so zero, one or several times in a frame, always before that frame's Update().
  5. Update(): once a frame.
  6. LateUpdate(): once a frame, after every Update().
  7. OnDisable(): every time the object is hidden, and before it is destroyed.
  8. OnDestroy(): once, when the object is destroyed.

Steps 4 to 6 repeat on every frame for as long as the object is active. A spawned object goes through the same list: Instantiate runs the copy's Awake() and OnEnable() before it returns, and the copy's Start() comes before its first Update().

Two habits follow from the order. Code in Awake() sets up an object's own fields in time for every other object's Start(). And physics code goes in FixedUpdate(), whose steps are always 0.02 seconds apart, however fast or slow the frames come.

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Unity Scripting Basics