Skip to content

API Interface WorldHandle

github-actions[bot] edited this page Dec 1, 2026 · 4 revisions

Interface: WorldHandle

Defined in: src/engine/core/worlds.ts:140

A handle on a World: the only cross-World API. It controls the World's lifetime and setup but never exposes its nodes, so Worlds stay isolated (ADR 0032).

Properties

alive

readonly alive: boolean;

Defined in: src/engine/core/worlds.ts:144

False from unload() (or destroy()) on. Methods on an unloaded handle throw.


holdPending

readonly holdPending: boolean;

Defined in: src/engine/core/worlds.ts:155

The next replacing load will hold: WorldConfig.start: "held", or a hold load still preparing.


loading

readonly loading: boolean;

Defined in: src/engine/core/worlds.ts:151

A load is in flight, from its first asset to its readiness (additive loads into a playing World included).


loadProgress

readonly loadProgress: LoadProgress | null;

Defined in: src/engine/core/worlds.ts:157

How far the current load has come (ADR 0616): the newest replacing load's while one is in flight, else the newest additive load's; null while nothing is loading.


name

readonly name: string;

Defined in: src/engine/core/worlds.ts:141


paused

readonly paused: boolean;

Defined in: src/engine/core/worlds.ts:159

Deprecated

Use state === "paused".


ready

readonly ready: boolean;

Defined in: src/engine/core/worlds.ts:153

No load is in flight and the latest reached readiness (ADR 0616). True before any load.


state

readonly state: "playing" | "held" | "activating" | "paused" | "unloading" | "destroyed";

Defined in: src/engine/core/worlds.ts:149

What the World does (ADR 0615): only playing steps its systems, scripts and physics; held waits for activate(), activating runs its deferred start() calls hidden, paused is stopped and silent.


tags

readonly tags: readonly WorldTag[];

Defined in: src/engine/core/worlds.ts:142

Methods

activate()

activate(): Promise<void>;

Defined in: src/engine/core/worlds.ts:178

Release a held World (ADR 0615): activating runs its deferred start() calls hidden, a few milliseconds a frame, then it plays. Resolves once it's playing.

Returns

Promise<void>


addresses()

addresses(): readonly string[];

Defined in: src/engine/core/worlds.ts:196

Where this World listens (ADR 0067). Empty if it doesn't.

Returns

readonly string[]


addSystem()

addSystem(name): void;

Defined in: src/engine/core/worlds.ts:180

Add a catalog system by name. Throws for unknown names.

Parameters

name

string

Returns

void


connect()

connect(
   server, 
   transport, 
   options?
): void;

Defined in: src/engine/core/worlds.ts:188

Join this World (client side) to server over a transport (ADR 0033): a World of this page, or the address of a server elsewhere, such as a dedicated server's "ws://host:7777" (ADR 0036).

Parameters

server

string | WorldHandle

transport

string

options?

Record<string, unknown>

Returns

void


destroy()

destroy(): void;

Defined in: src/engine/core/worlds.ts:212

Returns

void

Deprecated

Use unload(). Tears down at once, without the audio fade.


hasTag()

hasTag(tag): boolean;

Defined in: src/engine/core/worlds.ts:160

Parameters

tag

WorldTag

Returns

boolean


listen()

listen(transport, options?): Promise<string>;

Defined in: src/engine/core/worlds.ts:194

Make this World a server and listen over a transport (ADR 0067). Resolves with the address clients connect to; rejects with a reason. Options: port, host, path, address, maxConnections and timeouts. Throws if the World is a client.

Parameters

transport

string

options?

Record<string, unknown>

Returns

Promise<string>


load()

load(path, options?): Promise<void>;

Defined in: src/engine/core/worlds.ts:166

Load a scene into the World (ADR 0615). Resolves at the swap, at the end of a frame. Rejects with an AbortError when signal aborts or a later replacing load replaces it, and with a WorldUnloadedError when the World is unloaded first. hold (replacing loads only) enters held at the swap instead of going on playing.

Parameters

path

string

options?

WorldLoadOptions

Returns

Promise<void>


loadScene()

loadScene(path, options?): Promise<void>;

Defined in: src/engine/core/worlds.ts:168

Parameters

path

string

options?
additive?

boolean

Returns

Promise<void>

Deprecated

Use load(path, options).


onChange()

onChange(listener): () => void;

Defined in: src/engine/core/worlds.ts:218

Called after each change of state, loading, ready or holdPending. A state change is reported at the end of the World's frame (at once between frames); the loading flags when a load begins or settles. A change asked for inside a listener waits until the listeners have run. Returns the unsubscribe; listeners go when the World does.

Parameters

listener

(change) => void

Returns

() => void


pause()

pause(options?): void;

Defined in: src/engine/core/worlds.ts:203

Pausing a World stops its input and UI too: for a pause menu, set Time.timeScale = 0 instead. pause() is for a World nobody is looking at (the menu behind a match): it stops stepping, its sounds pause (faded over audioFadeMs, default a few milliseconds), and its network stays connected (ADR 0615). Server Worlds can't pause, and an activating World throws (await activate() first). A held World paused resumes held.

Parameters

options?
audioFadeMs?

number

Returns

void


removeSystem()

removeSystem(name): void;

Defined in: src/engine/core/worlds.ts:181

Parameters

name

string

Returns

void


resume()

resume(): void;

Defined in: src/engine/core/worlds.ts:205

Undo pause(): back to playing, or to held if it was held.

Returns

void


systems()

systems(): readonly string[];

Defined in: src/engine/core/worlds.ts:183

The World's systems by name, in execution order per phase.

Returns

readonly string[]


unload()

unload(): Promise<void>;

Defined in: src/engine/core/worlds.ts:210

Tear the World down (ADR 0615): alive is false at once, pending loads reject, its sounds fade out; resolves once it's destroyed. The Engine's last World can't be unloaded (dispose the Engine instead).

Returns

Promise<void>


whenReady()

whenReady(): Promise<void>;

Defined in: src/engine/core/worlds.ts:173

Resolves when no load is pending and the latest is ready; at once if nothing is loading. Rejects if the latest load failed, or the newest replacing load did (even when a later additive load succeeded).

Returns

Promise<void>

Clone this wiki locally