Skip to content

Engine

Defined in: Engine.ts:68

The top-level entry point. Owns the plugin registry, game loop, scene manager, and DI container.

new Engine(config?): Engine

Defined in: Engine.ts:126

EngineConfig

Engine

readonly assets: AssetManager

Defined in: Engine.ts:87

The asset manager.


readonly context: EngineContext

Defined in: Engine.ts:70

The dependency injection container.


readonly events: EventBus<EngineEvents>

Defined in: Engine.ts:74

The event bus.


readonly logger: Logger

Defined in: Engine.ts:78

The logger.


readonly loop: GameLoop

Defined in: Engine.ts:76

The game loop.


readonly sceneRandom: SceneRandomSource

Defined in: Engine.ts:80

Creates each scene’s RandomKey RNG and owns the seed it starts from.


readonly scenes: SceneManager

Defined in: Engine.ts:72

The scene manager.

_observeFrameEnd(observer): () => void

Defined in: Engine.ts:257

Internal

Register an observer that runs once at the very end of every frame, after EndOfFrame systems have run and destroyed entities have been removed. Nothing else runs between the observers and the start of the next frame.

Read-only. An observer reads engine state; it must not change it. Do not spawn or destroy entities, add or remove components, emit events, or push, pop or replace scenes from one. A change made here lands after this frame’s cleanup: an entity destroyed here stays in its scene until the next frame’s flush, an event emitted here is stamped with a frame whose waits have already been settled, and observers registered earlier never see it. Per-frame work that changes state belongs in a System or a component.

Observers run in registration order and receive the settled frame’s number (loop.frameCount). Each call goes through ErrorBoundary.wrapCallback: a throw is recorded and rethrown, which stops the loop like any other error that escapes a frame.

FrameEndObserver

A function that removes the observer. Calling it twice is harmless. The Inspector’s installer uses this to expire events.waitFor deadlines.

() => void


destroy(): void

Defined in: Engine.ts:433

Stop the engine. Destroys all scenes, plugins, and the game loop. One-way: the instance cannot be started again. Repeat calls are a no-op, so a host that tears down defensively (hot reload, component unmount) can call it without tracking whether it already did.

Scene teardown, system unregistration and plugin onDestroy are independent stages: a throw in one still lets the others run, so a failing scene onExit cannot leave a plugin holding its GPU context. The first error is rethrown once teardown has finished, and the rest are reported through Logger.

onDestroy runs for every plugin whose install() was called, in reverse install order (dependents first). A plugin start() never reached — because destroy() was called while an earlier install was awaiting — has nothing to release and is skipped.

Called from inside a frame, destroy() stops the loop at the running phase’s boundary: the systems of that phase finish, and the phases after it are skipped (see GameLoop.stop).

void


registerSceneHooks(hooks): () => void

Defined in: Engine.ts:229

Register scene lifecycle hooks. The returned function unregisters the hooks. Infrastructure plugins (renderer, physics, debug) register hooks in their install or onStart to set up and tear down per-scene state.

SceneHooks

() => void


start(): Promise<void>

Defined in: Engine.ts:315

Start the engine. Installs plugins in topological order, starts the game loop. Calling it again while running is a no-op.

An engine instance is single-use, so start() throws once the instance has reached a terminal state — destroy() has run, or an earlier start() rejected. Plugin install() registers services into a container that rejects duplicate keys, and onDestroy() releases resources the plugin cannot rebuild, so a second pass over the same instance cannot produce a working engine.

destroy() called while startup is still awaiting a plugin abandons the rest of the sequence: the loop never starts and no further hook runs.

Promise<void>


use(plugin): this

Defined in: Engine.ts:281

Register a plugin. Must be called before start().

Plugin

this

Coding agents: fetch https://yage.dev/llms.txt first and prefer the Markdown references it links over these HTML pages. This page's Markdown counterpart is /llms/packages/core.md.