Skip to content

Scripts ​

suity.script is the only script component type, and only *.component.ts (asset kind scriptComponent) can be mounted. Plain .ts files are dependencies for the bundle, not mountable scripts.

Minimal script ​

ts
import { ScriptComponent } from "@suity/engine-pixi/script";

export default class PlayerController extends ScriptComponent {
  private speed = 180;

  onStart() {
    this.log("player ready", this.node.name);
  }

  onUpdate(dt: number) {
    const dir = this.input.axis("MoveX");
    const body = this.node.container();
    body.x += dir * this.speed * dt;

    if (this.input.pressed("Jump")) {
      this.warn("jump is handled by platformer2d in game projects");
    }
  }

  onDestroy() {
    this.log("player destroyed");
  }
}

Scripts expose their class via default export. The build generates a stable runtimeKey and a manifest entry per script; the manifest declares sdkVersion: "1.0.0".

Lifecycle ​

CallbackWhenNotes
onStart()After mountingMaps to the unified handler's onLoad
onEnable()Component/node becomes enabledOptional
onUpdate(dt)Every framedt is in seconds
onDisable()Component/node becomes inactiveOptional
onDestroy()Stop or unmountRelease listeners and external resources

ScriptComponent implements the shared ComponentHandler lifecycle, so scripts and module components follow the same enabled / active semantics.

Available context ​

MemberTypePurpose
this.nodeNodeOwning node: query children, resolve(path), read/write components
this.sceneSceneScene-level queries, structural edits, mainCamera, signals
this.inputInputStateaxis / held / pressed / released
this.assetsScriptAssetsresolve / load assets
this.signalsScriptSignalsNode signal reads/writes, watching and provider registration
this.componentComponentHandleThe current suity.script component handle
this.componentRefstringStable componentRef of this mount

Use this.log() / this.warn() / this.error() instead of console, so messages land in the Play Output panel.

Mounting and builds ​

  • In the editor, add a script via Add Component → Script. It persists as { script: <asset uid> }.
  • Scripts mounted dynamically during Play write { runtimeScript, runtimeScriptName }; they have no asset UID, do not enter the scene document, dirty state or undo, and are destroyed on Stop.
  • Builds bundle all .component.ts files by default, including dynamic classes. The host does not embed a TypeScript compiler; the project's build:scripts runs the bundle.

Relationship to module components ​

Module handlers (Actor, Platformer 2D, ...) and ScriptComponent share the same ComponentHandler lifecycle and SDK Node / Scene / ComponentHandle. The differences are:

  • Modules declare compatibility through sdkApiVersion in their manifest.
  • Scripts are mounted by the scene document or at runtime.
  • A node can host several scripts, each mount with its own componentRef.

See the Script API.

Suity developer documentation · API generated by TypeDoc