Skip to content

Documentation / scene / RuntimeScript

Class: RuntimeScript<T>

Defined in: libs/scene/src/app/runtimescript.ts:296

Base class for runtime scripts that can be attached to a host object.

Lifecycle overview:

  • onCreated(): Called once per script instance right after construction, before any host is attached.
  • onAttached(host): Called each time this instance is attached to a host.
  • onUpdate(deltaTime, elapsedTime): Called every frame/tick while attached.
  • onDetached(host): Called when detached from a host.
  • onDestroy(): Called when the instance is no longer attached to any host and is about to be discarded.

Notes:

  • Hooks may return a Promise to perform asynchronous work (e.g., asset loading).
  • The generic host type T can be IDisposable or null. If null, the script may operate without a concrete host.

Type Parameters

T

T extends IDisposable | null

The host type that this script attaches to. Typically implements IDisposable.

Constructors

Constructor

new RuntimeScript<T>(): RuntimeScript<T>

Returns

RuntimeScript<T>

Methods

getScriptProperties()

static getScriptProperties(this): RuntimeScriptPropertyInfo[]

Defined in: libs/scene/src/app/runtimescript.ts:302

Gets merged serialized property metadata for this runtime script class.

Parameters

this

GenericConstructor

Returns

RuntimeScriptPropertyInfo[]

Declared parameter metadata for the current class.


onCreated()

onCreated(): void | Promise<void>

Defined in: libs/scene/src/app/runtimescript.ts:313

Called once after construction, before the first attachment to a host.

Use this to initialize internal state, allocate resources, or kick off asynchronous loading needed by the script.

Returns

void | Promise<void>

Optionally a Promise to await initialization.


onAttached()

onAttached(_host): void | Promise<void>

Defined in: libs/scene/src/app/runtimescript.ts:323

Called when the script is attached to a host.

This may be called multiple times if the same instance attaches to different hosts over its lifetime.

Parameters

_host

T

The host the script is being attached to.

Returns

void | Promise<void>

Optionally a Promise to await asynchronous setup.


onUpdate()

onUpdate(_deltaTime, _elapsedTime): void

Defined in: libs/scene/src/app/runtimescript.ts:332

Called every update/tick while the script is active.

Typical usage includes per-frame logic, animation, and input handling.

Parameters

_deltaTime

number

Time since last update in seconds.

_elapsedTime

number

Total elapsed time since start in seconds.

Returns

void


onDetached()

onDetached(_host): void

Defined in: libs/scene/src/app/runtimescript.ts:340

Called when the script is detached from a host.

Use this to stop host-specific behaviors and release host-bound resources.

Parameters

_host

T

The host the script is being detached from.

Returns

void


onDestroy()

onDestroy(): void

Defined in: libs/scene/src/app/runtimescript.ts:347

Called when the script has no remaining hosts and is about to be discarded.

Use this to release global resources and finalize the script's lifecycle. This is the terminal lifecycle hook for an instance.

Returns

void

Released under the MIT License.