Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 36 ยท C# Scripting

Lifecycle Methods: Awake, Start, Update and More

Learn the order of Unity's MonoBehaviour event methods: Awake, OnEnable, Start, Update, FixedUpdate, LateUpdate, OnDisable, OnDestroy, and which one to use for what.

A MonoBehaviour is not just a class: Unity manages its life. From the moment the object is created to the moment it is destroyed, Unity calls specific methods at specific times. Putting code in the right method is the difference between a script that works and one that throws a NullReferenceException on the first frame.

This lesson lists those methods in order, explains what belongs in each, and uses a runnable simulation to show the exact order for several objects. The Unity scripts are read-only; the stand-in imitates the engine's calls.

The order of events

flowchart TD
    A["Object created / scene loads"] --> B["Awake"]
    B --> C["OnEnable"]
    C --> D["Start (before the first Update)"]
    D --> E["FixedUpdate (0..n times per frame)"]
    E --> F["Update"]
    F --> G["LateUpdate"]
    G --> E
    G --> H["OnDisable"]
    H --> I["OnDestroy"]

Awake, OnEnable and Start run once at the beginning; the per-frame methods repeat; OnDisable and OnDestroy run at the end.

The methods one by one

Method When Typical use
Awake() When the object is loaded, even if the script component is disabled (but the GameObject must be active) Initialize yourself; cache GetComponent results; set up singletons
OnEnable() Each time the component becomes enabled (also right after Awake) Subscribe to events
Start() Once, just before the first Update, only if the component is enabled Initialize things that depend on other objects
FixedUpdate() Every physics step (0.02 s by default) Forces and Rigidbody movement
Update() Every frame Input, game logic, timers
LateUpdate() Every frame after all Updates Follow cameras, last-moment adjustments
OnDisable() Each time the component is disabled or the object is destroyed Unsubscribe from events
OnDestroy() When the object is destroyed (scene unload, Destroy, quit) Final cleanup

Others you will meet: OnCollisionEnter and OnTriggerEnter (physics), OnMouseDown, OnBecameVisible, OnApplicationPause, OnApplicationQuit, OnGUI and OnValidate (editor only, called when a value changes in the Inspector).

Awake versus Start

Both run once at the beginning, so which one should you use? Think in two phases:

  1. Awake phase: Unity calls Awake on every active object in the scene.
  2. Start phase: Then Start is called on every object, just before its first Update.

Because all Awakes finish before any Start, the rule is:

  • In Awake: set up your own data and references to things on the same object.
  • In Start: use other objects, because their Awake has already run.
C#
using UnityEngine;

public class Player : MonoBehaviour
{
    public static Player Instance;
    public int health;

    void Awake()
    {
        Instance = this;       // other scripts can rely on this in Start
        health = 100;
    }
}

public class HealthBar : MonoBehaviour
{
    void Start()
    {
        Debug.Log("Player health: " + Player.Instance.health);   // safe: Player.Awake already ran
    }
}

If HealthBar read Player.Instance in its own Awake, it might run before the player's Awake, and Instance would still be null. The order of Awake calls between different scripts is not guaranteed unless you set Script Execution Order in Project Settings.

OnEnable and OnDisable: the event pair

OnEnable runs every time the component is turned on, and OnDisable every time it is turned off (including at destruction). That symmetry is perfect for subscribing to and unsubscribing from events, so you never leave a dead object listening:

C#
using System;
using UnityEngine;

public class Coin : MonoBehaviour
{
    public static event Action<int> Collected;     // simple global event

    public void Pickup() => Collected?.Invoke(10);
}

public class ScoreDisplay : MonoBehaviour
{
    int score;

    void OnEnable()  { Coin.Collected += AddScore; }
    void OnDisable() { Coin.Collected -= AddScore; }

    void AddScore(int amount) { score += amount; Debug.Log("Score: " + score); }
}

Without the unsubscribe, a destroyed ScoreDisplay would still be called by Collected, causing errors or memory leaks.

Simulating the order of calls

The following program is a mini engine: it creates three objects, then calls their methods in the same order that Unity does. Read the output carefully; notice that every Awake happens before any Start.

C# Lifecycle order for several objects (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

The real engine interleaves Awake and OnEnable per object (each object gets Awake then OnEnable before the next object starts), while Start runs later for everybody. This model keeps that two-phase structure, which is what you rely on in practice.

A common bug, reproduced

The next stand-in shows the "null on first frame" problem: a Hud that reads the player's data in Awake, which depends on the order of the calls, versus in Start, which is always safe.

C# Awake order bug versus Start (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

In real Unity the first line would be a NullReferenceException if you dereferenced Instance. Moving that read to Start removes the dependency on call order.

Inactive objects and disabled scripts

  • If the GameObject is inactive when the scene loads, none of Awake, OnEnable or Start run until it is activated.
  • If only the component is disabled, Awake runs but OnEnable and Start wait until you enable it. Update never runs while disabled.
  • Start runs only once in the object's life, even if you disable and re-enable it; OnEnable runs every time.
  • A script instantiated from a prefab gets Awake and OnEnable immediately inside Instantiate, and Start just before the next Update.

The constructor trap

Do not use C# constructors or field initializers that call Unity APIs in a MonoBehaviour. Unity creates instances itself, sometimes on a loading thread or in the editor, where the Unity API is not ready. Initialize in Awake or Start. A field like Vector3 start = new Vector3(0,1,0); is fine; Rigidbody rb = GetComponent<Rigidbody>(); as a field initializer is not.

Choosing the right method

  • Cache GetComponent results in Awake.
  • Read other objects' data in Start.
  • Subscribe and unsubscribe in OnEnable / OnDisable.
  • Read input in Update, move Rigidbodies in FixedUpdate.
  • Move cameras in LateUpdate, after their targets have moved.
  • Clean up in OnDestroy; do not call Destroy on yourself in OnDestroy.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Script A reads data that script B creates in its Awake. Where should A read it for safety?

    All Awake methods run before any Start, so Start can safely use data that other scripts set up in Awake.
  2. 2. Which pair is best for subscribing to and unsubscribing from events?

    OnEnable and OnDisable are symmetrical and run every time the component toggles, so listeners never outlive the component.
  3. 3. How many times does Start run in an object's life?

    Start runs once, just before the first Update. OnEnable can run many times.
  4. 4. Where do you apply physics forces to a Rigidbody?

    FixedUpdate runs in step with the physics simulation.

Summary

  • Order: Awake, OnEnable, Start, then FixedUpdate/Update/LateUpdate repeatedly, then OnDisable and OnDestroy.
  • All Awake calls happen before any Start; use Awake for self-setup and Start for cross-object setup.
  • Pair OnEnable with OnDisable for events.
  • Inactive objects and disabled components delay or skip these calls.
  • Never initialize Unity components in constructors or field initializers.

Next: Inspector Fields and Attributes