menu_bookDocumentation
Component Lifecycle: Full Callback Order — OnAwake, OnEnabled, OnStart, OnUpdate, OnFixedUpdate, OnDisabled, OnDestroy
Component Lifecycle: Full Callback Order
s&box components have a well-defined lifecycle. Understanding the exact order prevents subtle bugs.
Callback Order
| Callback | When Called |
|---|---|
| OnAwake() | Once, when the component first becomes active. Called before OnEnabled. Interpolation is disabled during this call. |
| OnEnabled() | After OnAwake, and every time the component transitions from disabled → enabled. Interpolation is disabled during this call. |
| OnStart() | Once, before the first OnUpdate or OnFixedUpdate. Called lazily — deferred until the next update tick. |
| OnUpdate() | Every frame while enabled. Not called on a dedicated server. |
| OnFixedUpdate() | On a fixed interval (physics tick rate). Time.Delta is the fixed interval. |
| OnPreRender() | Every frame, just before rendering. Not called on a dedicated server or headless. |
| OnDisabled() | Every time the component transitions from enabled → disabled. |
| OnDestroy() | Once, when the component is destroyed. After this, GameObject is set to null. |
Key Behaviors
- OnAwake is only called if ShouldExecute is true. Components on a PrefabCacheScene never execute. Components on an editor scene only execute if they implement ExecuteInEditor. Components implementing DontExecuteOnServer are skipped on dedicated servers.
- OnStart is deferred — it runs at the start of the next update tick, not immediately when the component is enabled. It is guaranteed to run before OnUpdate or OnFixedUpdate.
- OnEnabled and OnDisabled are guarded against double-firing. The engine tracks _onEnabled internally.
- Interpolation is explicitly disabled during OnAwake, OnEnabled, OnDisabled, and OnStart to prevent transform artifacts when objects are created inside a fixed update context.
- OnDestroy exceptions are caught and logged — they do not propagate.
- After OnDestroy, IsValid returns false because GameObject is set to null.
Action Graph Callbacks
Components also expose Action properties for no-code use:
- OnComponentEnabled, OnComponentStart, OnComponentUpdate, OnComponentFixedUpdate, OnComponentDisabled, OnComponentDestroy
These are only invoked when !Scene.IsEditor.
Example
CSHARP
public class MyComponent : Component
{
protected override void OnAwake()
{
// Runs once. Transform interpolation is disabled here.
Log.Info( "Awake" );
}
protected override void OnEnabled()
{
// Runs each time we become active.
Log.Info( "Enabled" );
}
protected override void OnStart()
{
// Runs once, before first Update.
Log.Info( "Start" );
}
protected override void OnUpdate()
{
// Every frame.
}
protected override void OnFixedUpdate()
{
// Fixed timestep. Time.Delta is the fixed interval.
}
protected override void OnDisabled()
{
Log.Info( "Disabled" );
}
protected override void OnDestroy()
{
// After this, IsValid == false.
Log.Info( "Destroyed" );
}
}
Was this helpful?