Skip to content

Behaviour Lifecycle & Events

Behaviour is dispatched by the ScriptBehaviourSystem each frame. Knowing the precise order of hooks helps you place state setup, simulation, and cleanup correctly.

Frame order

World.update(dt)
  ├── ObjectManagementSystem        # parent reconciliation, entity lifecycle
  ├── (geometry / material systems)
  ├── (custom user systems)
  ├── ScriptBehaviourSystem
  │     ├── for each enabled script:
  │     │     ├── if first run → init()
  │     │     └── onUpdate()
  ├── (sync systems)
  ├── AnimationSystem
  ├── TransformSyncSystem
  └── RenderSystem

This ordering means:

  • this.transform mutations in onUpdate() are picked up the same frame by TransformSyncSystem and applied to the three.js object.
  • Animation runs after scripts, so animating a value will overwrite a script's mutation on the same property.

Hook reference

HookOverride?FrequencyRuns in editor?Purpose
init()Yes (protected)Once before first onUpdateOnly when executeInEditor: trueDefault and validate data, cache references
onUpdate()Yes (protected)Every frameOnly when executeInEditor: truePer-frame logic
dispose()YesOnce on detach/destroyOnly when executeInEditor: trueRelease timers, listeners, resources
onSelect() / onDeselect()OptionalEditor selection togglesYesUX-only hooks
onTargetFound() / onTargetLost()OptionalImage trackingNoReact to AR target visibility

Set executeInEditor: true on a script entry in the inspector to opt a script into the full lifecycle in editor mode. See Running scripts in the editor.