Lesson 2 of 9 · 26m
The Scripting Lifecycle: Awake, Start, Update, and Friends
Master Unity's event order so initialization, physics, rendering, and object destruction happen when you think they do.
Most Unity bugs that feel random are lifecycle bugs. A value is read before initialization. A physics force is applied in the visual frame callback. A destroyed object receives one more event. Unity is deterministic enough to debug, but only if you respect the order in which the engine drives your scripts.
The lifecycle is a contract
The important runtime order looks like this:
Awake object initialization, every active instance
OnEnable subscription and activation behavior
Start first-frame setup, after Awake across objects
FixedUpdate physics timestep, zero or more times per frame
Update visual/gameplay frame, once per rendered frame
LateUpdate camera and follow-up work after Update
OnDisable unsubscribe and deactivation behavior
OnDestroy final cleanup before object destructionThe details matter. Every Awake runs before any Start for objects created in the same batch, which makes Awake the place to wire up internal references and Start the safer place to depend on neighbors.
Use Awake for self, Start for others
public class Health : MonoBehaviour
{
public event Action<int> Changed;
private int current;
private void Awake()
{
current = maxValue;
}
private void Start()
{
Changed?.Invoke(current);
}
}In Awake, initialize fields you own. In Start, publish or consume state that may depend on other scripts having completed their own Awake.
FixedUpdate is not "Update but smoother"
FixedUpdate runs on a fixed timestep and may run zero, one, or several times before a rendered frame. Physics belongs there because forces and collision resolution are simulation concerns:
private void FixedUpdate()
{
rb.MovePosition(rb.position + moveInput * speed * Time.fixedDeltaTime);
}Use Time.fixedDeltaTime in FixedUpdate. Use Time.deltaTime in Update. Mixing them produces speed that changes with framerate or physics settings.
Destruction is deferred enough to matter
Destroy(obj) does not vaporize memory in the same line. Destruction happens after the current update loop. Guard long-lived callbacks and coroutines, unsubscribe in OnDisable, and never assume a cached reference remains valid forever.
Field notes
- Script execution order settings are a last resort, not an architecture. They hide coupling and make future refactors hazardous.
OnEnablecan run more often thanAwake; pooled objects are activated repeatedly.- Do not start physics work from
Startif the object may be spawned during gameplay before colliders finish initializing. - Log lifecycle calls once while learning, then remove the logs. Order is easier to understand empirically than from forum folklore.
Was this lesson helpful?