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
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
| Callback | When | Notes |
|---|---|---|
onStart() | After mounting | Maps to the unified handler's onLoad |
onEnable() | Component/node becomes enabled | Optional |
onUpdate(dt) | Every frame | dt is in seconds |
onDisable() | Component/node becomes inactive | Optional |
onDestroy() | Stop or unmount | Release listeners and external resources |
ScriptComponent implements the shared ComponentHandler lifecycle, so scripts and module components follow the same enabled / active semantics.
Available context
| Member | Type | Purpose |
|---|---|---|
this.node | Node | Owning node: query children, resolve(path), read/write components |
this.scene | Scene | Scene-level queries, structural edits, mainCamera, signals |
this.input | InputState | axis / held / pressed / released |
this.assets | ScriptAssets | resolve / load assets |
this.signals | ScriptSignals | Node signal reads/writes, watching and provider registration |
this.component | ComponentHandle | The current suity.script component handle |
this.componentRef | string | Stable 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.tsfiles by default, including dynamic classes. The host does not embed a TypeScript compiler; the project'sbuild:scriptsruns 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
sdkApiVersionin 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.
