Skip to content

@modoki/engine / index / SceneManager

Interface: SceneManager

Public surface of the sceneManager singleton. See the module doc above.

Scene & Prefabs

getCurrent()

getCurrent(): Scene | null

The currently-active scene. null until the first loadScene() resolves. Returns the PRIMARY scene — the one loadScene(path) was called with, as opposed to a base loaded additively alongside it.

Returns

Scene | null


getCurrentBaseScene()

getCurrentBaseScene(): string | undefined

The baseScene guid ref of the currently-active scene, if any.

Returns

string | undefined


getLoadedScenes()

getLoadedScenes(): ReadonlyMap<number, LoadedSceneEntry>

Every scene currently loaded into the active world — the primary plus any base scenes in its chain.

Returns

ReadonlyMap<number, LoadedSceneEntry>


getNext()

getNext(): Scene | null

The scene currently preloading (if any).

Returns

Scene | null


loadScene()

loadScene(path, opts?): Promise<void>

Load a scene file. Cancels any in-flight load. Resolves when the swap is complete and the new scene is active. Rejects if the load fails or is aborted (the current scene remains untouched on failure).

Parameters

path

string

opts?

SceneLoadOptions

Returns

Promise<void>


registerBeforeSwap()

registerBeforeSwap(hook): void

Register an async hook that runs after entities are spawned into the staging world but before the atomic swap. Use for shader prewarm.

Parameters

hook

BeforeSwapHook

Returns

void


registerSceneCallback()

registerSceneCallback(pathPattern, callback): void

Register a callback to run after a specific scene loads (by path or substring match). Use '*' as path to match all scenes.

Parameters

pathPattern

string

callback

() => void

Returns

void


resetForTesting()

resetForTesting(): void

For tests: reset the sceneId counter so test runs are deterministic.

Returns

void


unloadAll()

unloadAll(): Promise<void>

For tests + shutdown. Releases everything and resets the manager.

Returns

Promise<void>


unregisterBeforeSwap()

unregisterBeforeSwap(hook): void

Remove a previously-registered beforeSwap hook.

Parameters

hook

BeforeSwapHook

Returns

void


unregisterSceneCallback()

unregisterSceneCallback(pathPattern): void

Remove a previously registered scene callback.

Parameters

pathPattern

string

Returns

void

Built with Modoki.