Script Overview

Overview

Animation scripts are a first-class part of animationData and run through one shared command path.

  • Script data is stored in animationData.scripts.
  • Script actions use strict schema validation before execution.
  • State-machine runtime and external API paths reuse the same command dispatcher.

Supported Hooks

  • onRun
    • Triggered when playStateMachine(machineId) starts and script bindings match that machine.
  • onStateChange
    • Triggered after a state transition is selected and applied.

You can also call editor.animation.runScriptHook(scriptId, hook, context) directly.

Supported Actions

  • set-input
  • fire-trigger
  • set-object-property
  • seek-timeline
  • play-state-machine
  • set-script-input

set-script-input updates script-local inputs. Other actions are dispatched through the shared animation command executor.

Script Inputs

Script input types:

  • boolean
  • number (finite numbers only)
  • trigger (boolean pulse: true -> false)
  • string

Defaults are validated against declared input type. Use fireScriptTrigger(scriptId, inputId) to pulse trigger inputs deterministically.

Binding Rules

Scripts can bind to:

  • stateMachine
  • timeline
  • object
  • global

For state-machine hook auto-run (onRun, onStateChange), scripts execute when binding is global or matches the active state machine id. bindScript(scriptId, binding) returns a stable binding id that can be removed with unbindScript(scriptId, bindingId).

Diagnostics

Use editor.animation.getScriptDiagnostics(scriptId) to inspect last hook execution results.

Each entry includes:

  • action payload
  • ok status
  • execution message
  • execution timestamp