menu_bookDocumentation
s&box Component Lifecycle: Exact Execution Order and Internal Guards
s&box Component Lifecycle: Exact Execution Order and Internal Guards
Derived directly from Component.cs and Component.Update.cs in the s&box engine source.Execution Order
- OnAwake() — Called once when the Component is first initialized. Runs inside GameTransform.DisableInterpolation() scope, so Transform changes here won't be interpolated.
- OnEnabled() — Called after OnAwake or whenever the component transitions from disabled → enabled. Also runs inside DisableInterpolation().
- OnStart() — Called once before the first OnUpdate(). Deferred until the first update tick after the component becomes active. Also runs inside DisableInterpolation().
- OnUpdate() — Called every frame while enabled.
- OnFixedUpdate() — Called at a fixed interval (physics tick rate). Time.Delta is the fixed interval here.
- OnPreRender() — Called before rendering. Not called on dedicated servers (Application.IsHeadless).
- OnDisabled() — Called when the component transitions from enabled → disabled.
- OnDestroy() — Called once when the component is destroyed.
Key Internal Guards
- OnStart() is only called once (_startCalled flag). It fires from inside InternalUpdate() or InternalFixedUpdate(), meaning it can fire from either context.
- OnEnabled() and OnDisabled() are guarded by _onEnabled flag — they will never double-fire.
- Components on a PrefabCacheScene never execute (ShouldExecute returns false).
- Components marked DontExecuteOnServer won't execute on dedicated servers.
- Components that are not ExecuteInEditor won't execute in editor scenes.
- OnValidate() is called after deserialization and on property changes in the editor.
- OnRefresh() is called after a Component is refreshed from a network snapshot.
Callback Batching
Lifecycle callbacks (OnAwake, OnEnabled, OnDisabled, OnDestroy, OnValidate) are queued via CallbackBatch rather than called immediately. This prevents re-entrant issues during scene loading or destruction.Action-Based Callbacks
Components expose action properties for use in ActionGraph / no-code contexts:- OnComponentEnabled, OnComponentDisabled, OnComponentDestroy
- OnComponentStart, OnComponentUpdate, OnComponentFixedUpdate
Was this helpful?