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(), or onPausedUpdate() while paused
├── (sync systems)
├── AnimationSystem, BoneHoldSystem, IKSystem
├── TransformSyncSystem
├── ScriptLateUpdateSystem
│ └── onLateUpdate()
├── CameraRigSystem # Camera Rigs and cutscenes
└── RenderSystemThis ordering means:
this.transformmutations inonUpdate()are picked up the same frame byTransformSyncSystemand applied to the three.js object.- Animation runs after scripts, so animating a value will overwrite a script's mutation on the same property.
onLateUpdate()runs once everything has moved and reached three.js, which is where a camera belongs. See Camera Rigs.
Hook reference
| Hook | Override? | Frequency | Runs in editor? | Purpose |
|---|---|---|---|---|
init() | Yes (protected) | Once before first onUpdate | No | Default and validate data, cache references |
onUpdate() | Yes (protected) | Every frame, unless paused | No | Per-frame logic |
onLateUpdate() | Yes (protected) | Every frame, after everything has moved, unless paused | No | Cameras, and anything that follows something else |
onPausedUpdate() | Yes (protected) | Every frame while paused, instead of onUpdate() | No | Pause-menu logic |
onPause() / onResume() | Optional | When the game pauses and resumes | No | React to a pause |
dispose() | Yes | Once on detach/destroy | No | Release timers, listeners, resources |
onSelect() / onDeselect() | Optional | Editor selection toggles | Yes | UX-only hooks |
onTargetFound() / onTargetLost() | Optional | Image tracking | No | React to AR target visibility |
Behaviours never run in the editor. For a visual that must render and animate in the editor, use a Script Object.
While the game is paused
world.pause() swaps onUpdate() for onPausedUpdate() until world.resume():
onUpdate() # running
onPause() # once, from inside world.pause()
onPausedUpdate() # every frame, with this.deltaTime valid
onPausedUpdate()
onResume() # once, from inside world.resume()
onUpdate() # running againonPause and onResume reach every script, hidden entities included. onPausedUpdate skips hidden entities, as onUpdate does.
A pause or resume takes effect at once, but a script that hasn't run yet that frame gets neither per-frame hook until the next one. That is why one key press can't both open and close a menu.
Other hooks may stop too: onSelect, onSelectStart, onGrab and hand poses don't fire while paused, and UI and multiplayer hooks do. See Pausing the Game.
When a hook throws
The engine catches the error, so one broken script never stops the frame or other scripts. What happens next depends on the hook:
- Load,
init()oronUpdate(): the engine disposes the instance, sets the entry'sruntimeStateto"error"with the message inruntimeMessage, and waits about one second before it loads and initialises the script again. A script that throws on every frame therefore restarts about once a second, not 60 times. - Event hooks (
onSelect,onUiPress,onGrab,onXRSessionStart,onPause,onPausedUpdateand the rest): the instance keeps running and the next event calls the hook again.
Either way the engine logs the first occurrence of each distinct error with console.error, naming the entity, class and phase. Subscribe with world.onScriptError to receive the same reports in code.

