Component Lifecycle
Component lifecycle callbacks separate initialization, fixed simulation, frame updates, rendering, activation, and cleanup.
Callback order
For an active component, the lifecycle is:
Awakewhen the component attaches.OnEnablewhen the component becomes active and enabled.Startbefore its first fixed update, update, or render.FixedUpdatezero or more times for each game update.Updateonce for the game update.LateUpdateafter regular updates.Renderduring drawing.OnDisablewhen the component or its GameObject becomes inactive, or before destruction.OnDestroyonce when the component is removed or its GameObject is destroyed.
Awake, Start, and OnDestroy run once. OnEnable and OnDisable can run more than once as activation changes.
Choose the right callback
| Callback | Use it for |
|---|---|
Awake |
Internal initialization that does not depend on later component configuration |
OnEnable |
Subscribing to events or starting work that must pause while disabled |
Start |
Initialization that reads other components or values assigned after AddComponent |
FixedUpdate |
Fixed-rate simulation |
Update |
Input, timers, and frame-rate-aware behavior |
LateUpdate |
Camera following and final transform adjustments |
Render |
Submitting draw commands to the active sprite batch |
OnDisable |
Unsubscribing or pausing active work |
OnDestroy |
Final component cleanup |
Configuration before Start
Start is intentionally deferred, so callers can configure a component after adding it:
var follower = cameraObject.AddComponent<CameraFollower>();
follower.Target = player.Transform;
follower.Smoothing = 8f;
public sealed class CameraFollower(GameObject gameObject, Camera2D camera)
: Component(gameObject)
{
public Transform? Target { get; set; }
public float Smoothing { get; set; }
public override void Start()
{
ArgumentNullException.ThrowIfNull(Target);
}
public override void LateUpdate(double deltaTime)
{
var amount = 1f - MathF.Exp(-Smoothing * (float)deltaTime);
camera.Position = Vector2.Lerp(camera.Position, Target!.Position, amount);
}
}
Activation and cleanup
Set Enabled when one behavior should pause. Set GameObject.Active when every component on the object should pause. In both cases, inactive components skip fixed updates, updates, late updates, and rendering.
If a component subscribes in OnEnable, unsubscribe in OnDisable. Reserve OnDestroy for cleanup that happens only once. Scene unload invokes the destruction path for every remaining object before its scoped services are disposed.