Scene
Defined in: Scene.ts:142
Scenes own entities and define lifecycle hooks. Each scene is a self-contained world with its own entity pool.
Extended by
Section titled “Extended by”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Scene():
Scene
Returns
Section titled “Returns”Scene
Properties
Section titled “Properties”_spawnInert
Section titled “_spawnInert”_spawnInert:
boolean=false
Defined in: Scene.ts:268
Internal
Set by Entity.spawnChild while the parent is dormant. A spawn runs
setup() before the parent link exists, so without this the child would
be briefly active and fire enable hooks it is about to undo.
Consumed by the first entity the spawn creates — that is the child itself,
built before its setup() runs. Anything setup() spawns on its own is a
separate entity with no parent to resync it, so it must not inherit the
suppression and stay dormant forever.
defaultTransition?
Section titled “defaultTransition?”
readonlyoptionaldefaultTransition?:SceneTransition
Defined in: Scene.ts:169
Default transition used when this scene is the destination of a push/pop/replace.
abstractreadonlyname:string
Defined in: Scene.ts:144
Name for debugging/inspection.
pauseBelow
Section titled “pauseBelow”
readonlypauseBelow:boolean=true
Defined in: Scene.ts:147
Whether scenes below this one in the stack should be paused. Default: true.
preload?
Section titled “preload?”
readonlyoptionalpreload?: readonlyAssetHandle<unknown>[]
Defined in: Scene.ts:166
Asset handles to load before onEnter(). Override in subclasses.
timeScale
Section titled “timeScale”timeScale:
number=1
Defined in: Scene.ts:238
Time scale multiplier for this scene. 1.0 = normal, 0.5 = half speed. Default: 1.
transparentBelow
Section titled “transparentBelow”
readonlytransparentBelow:boolean=false
Defined in: Scene.ts:163
Whether scenes below this one should still render. Default: false.
When false (the default), the renderer hides every below-stack scene
tree — both world-space layers AND screen-space layers (HUD, UI panels,
dialogs). Set true for pause menus, dialog overlays, or any scene
that should be drawn on top of a still-visible game world.
The chain composes: a below scene stays visible only while every scene
above it has transparentBelow = true. While a scene transition is
running, both the outgoing and incoming scenes render regardless of
this flag so transitions like crossFade keep working; the chain is
reapplied when the transition ends.
Accessors
Section titled “Accessors”assets
Section titled “assets”Get Signature
Section titled “Get Signature”get assets():
AssetManager
Defined in: Scene.ts:296
Convenience accessor for the AssetManager.
Returns
Section titled “Returns”context
Section titled “context”Get Signature
Section titled “Get Signature”get context():
EngineContext
Defined in: Scene.ts:271
Access the EngineContext.
Returns
Section titled “Returns”isPaused
Section titled “isPaused”Get Signature
Section titled “Get Signature”get isPaused():
boolean
Defined in: Scene.ts:276
Whether this scene is effectively paused (manual pause or paused by stack).
Returns
Section titled “Returns”boolean
isTransitioning
Section titled “isTransitioning”Get Signature
Section titled “Get Signature”get isTransitioning():
boolean
Defined in: Scene.ts:290
Whether a scene transition is currently running.
Returns
Section titled “Returns”boolean
paused
Section titled “paused”Get Signature
Section titled “Get Signature”get paused():
boolean
Defined in: Scene.ts:185
Manual pause flag. Set by game code to pause this scene regardless of
stack position. Assigning it fires onPause/onResume when the
effective pause state (isPaused) flips — writes that don’t change the
flag, or that are masked by a stack pause, fire nothing. Writes before
the scene is pushed fire nothing either; the push itself fires onPause
for a scene entering paused.
To start a scene paused, set paused = true before pushing it — the push
fires onPause once. Do NOT write paused from inside a lifecycle hook
(onEnter/onExit/onPause/onResume): that write races the stack
transition’s own pause diff, so onPause/onResume can fire twice or
unpaired. A dev-mode warning flags this case.
Returns
Section titled “Returns”boolean
Set Signature
Section titled “Set Signature”set paused(
value):void
Defined in: Scene.ts:189
Parameters
Section titled “Parameters”boolean
Returns
Section titled “Returns”void
Methods
Section titled “Methods”_addExistingEntity()
Section titled “_addExistingEntity()”_addExistingEntity(
entity):void
Defined in: Scene.ts:575
Internal
Add an existing entity to this scene (used by Entity.addChild for auto-scene-membership).
Parameters
Section titled “Parameters”entity
Section titled “entity”Returns
Section titled “Returns”void
_clearScopedServices()
Section titled “_clearScopedServices()”_clearScopedServices():
void
Defined in: Scene.ts:811
Internal
Clear all scene-scoped services. Called by the SceneManager after
afterExit hooks run, so plugin cleanup code still sees scoped state.
Returns
Section titled “Returns”void
_destroyAllEntities()
Section titled “_destroyAllEntities()”_destroyAllEntities():
void
Defined in: Scene.ts:906
Internal
Destroy all entities — used during scene exit. Applies the same destroy
contract as _flushDestroyQueue: entities are marked destroyed, torn
down, detached from the scene, and entity:destroyed is emitted once
per entity (including entities queued but not yet flushed). Clears the
identity index in bulk; per-entity key removal in _flushDestroyQueue
is the in-game path.
Returns
Section titled “Returns”void
_flushDestroyQueue()
Section titled “_flushDestroyQueue()”_flushDestroyQueue():
void
Defined in: Scene.ts:854
Internal
Flush the destroy queue — destroy pending entities. Called by the engine during the endOfFrame phase.
Returns
Section titled “Returns”void
_observeEntityEvent()
Section titled “_observeEntityEvent()”_observeEntityEvent(
eventName,data,entity):void
Defined in: Scene.ts:716
Internal
Observe entity-scoped event emissions after they dispatch locally and
bubble to the scene. Tooling only; game code should keep using on().
Parameters
Section titled “Parameters”eventName
Section titled “eventName”string
unknown
entity
Section titled “entity”Returns
Section titled “Returns”void
_onEntityEvent()
Section titled “_onEntityEvent()”_onEntityEvent(
eventName,data,entity):void
Defined in: Scene.ts:691
Internal
Called by Entity.emit() for bubbling entity events to the scene.
Parameters
Section titled “Parameters”eventName
Section titled “eventName”string
unknown
entity
Section titled “entity”Returns
Section titled “Returns”void
_queueDestroy()
Section titled “_queueDestroy()”_queueDestroy(
entity):void
Defined in: Scene.ts:595
Internal
Add an entity to the destroy queue. Called by Entity.destroy().
Parameters
Section titled “Parameters”entity
Section titled “entity”Returns
Section titled “Returns”void
_registerKey()
Section titled “_registerKey()”_registerKey(
entity,key):void
Defined in: Scene.ts:541
Internal
Internal: register a key on a freshly spawned entity. Throws on
duplicate so callers (Scene.spawn) can abort before adding to
this.entities or emitting entity:created.
Parameters
Section titled “Parameters”entity
Section titled “entity”string
Returns
Section titled “Returns”void
_registerPool()
Section titled “_registerPool()”_registerPool(
pool):void
Defined in: Scene.ts:559
Internal
Internal: track a pool so the scene can dispose it on exit. Called by the
EntityPool constructor.
Parameters
Section titled “Parameters”ScenePool
Returns
Section titled “Returns”void
_registerScoped()
Section titled “_registerScoped()”_registerScoped<
T>(key,value):void
Defined in: Scene.ts:773
Internal
Internal alias for registerScoped kept so existing plugin/test code
doesn’t churn. Prefer registerScoped in new code.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”ServiceKey<T>
T
Returns
Section titled “Returns”void
_resolveScoped()
Section titled “_resolveScoped()”_resolveScoped<
T>(key):T|undefined
Defined in: Scene.ts:802
Internal
Internal alias for tryResolveScoped. Prefer tryResolveScoped in
new code.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”ServiceKey<T>
Returns
Section titled “Returns”T | undefined
_setContext()
Section titled “_setContext()”_setContext(
context):void
Defined in: Scene.ts:819
Internal
Set the engine context. Called by SceneManager when the scene is pushed.
Parameters
Section titled “Parameters”context
Section titled “context”Returns
Section titled “Returns”void
_setEntityEventObserver()
Section titled “_setEntityEventObserver()”_setEntityEventObserver(
observer?):void
Defined in: Scene.ts:781
Internal
Install or clear a tooling-only observer for bubbled entity events.
Parameters
Section titled “Parameters”observer?
Section titled “observer?”(eventName, data, entity) => void
Returns
Section titled “Returns”void
_unregisterPool()
Section titled “_unregisterPool()”_unregisterPool(
pool):void
Defined in: Scene.ts:567
Internal
Internal: stop tracking a pool. Called by EntityPool.dispose.
Parameters
Section titled “Parameters”ScenePool
Returns
Section titled “Returns”void
afterRestore()?
Section titled “afterRestore()?”
optionalafterRestore(data,resolve):void
Defined in: Scene.ts:750
Called after entities are restored during save/load. Rebuild non-serializable state here.
Parameters
Section titled “Parameters”unknown
resolve
Section titled “resolve”Returns
Section titled “Returns”void
destroyEntity()
Section titled “destroyEntity()”destroyEntity(
entity):void
Defined in: Scene.ts:587
Mark an entity for destruction. Deferred to endOfFrame flush.
Parameters
Section titled “Parameters”entity
Section titled “entity”Returns
Section titled “Returns”void
emit()
Section titled “emit()”Call Signature
Section titled “Call Signature”emit(
token):void
Defined in: Scene.ts:666
Emit a typed event at the scene level. Scene-level on handlers fire
with entity = undefined to indicate there’s no emitting entity.
Symmetric to Entity.emit but for scene-scoped signalling.
Parameters
Section titled “Parameters”EventToken<void>
Returns
Section titled “Returns”void
Call Signature
Section titled “Call Signature”emit<
T>(token,data):void
Defined in: Scene.ts:667
Emit a typed event at the scene level. Scene-level on handlers fire
with entity = undefined to indicate there’s no emitting entity.
Symmetric to Entity.emit but for scene-scoped signalling.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”EventToken<T>
T
Returns
Section titled “Returns”void
findByKey()
Section titled “findByKey()”findByKey<
E>(key):E|undefined
Defined in: Scene.ts:529
Look up an entity by its stable identity key, scoped to this scene.
Returns undefined for unknown or already-destroyed entities.
Type Parameters
Section titled “Type Parameters”Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”E | undefined
findEntities()
Section titled “findEntities()”Call Signature
Section titled “Call Signature”findEntities<
T>(filter):Entity&T[]
Defined in: Scene.ts:626
Find active entities matching a filter. Trait filter narrows the return type.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”filter
Section titled “filter”EntityFilter & object
Returns
Section titled “Returns”Entity & T[]
Call Signature
Section titled “Call Signature”findEntities(
filter?):Entity[]
Defined in: Scene.ts:627
Find active entities matching a filter. Trait filter narrows the return type.
Parameters
Section titled “Parameters”filter?
Section titled “filter?”Returns
Section titled “Returns”Entity[]
findEntitiesByTag()
Section titled “findEntitiesByTag()”findEntitiesByTag(
tag):Entity[]
Defined in: Scene.ts:617
Find active entities by tag.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Entity[]
findEntity()
Section titled “findEntity()”findEntity(
name):Entity|undefined
Defined in: Scene.ts:609
Find an active entity by name (first match).
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Entity | undefined
getEntities()
Section titled “getEntities()”getEntities():
ReadonlySet<Entity>
Defined in: Scene.ts:604
Every entity in the scene, dormant ones included — this is the set save and teardown walk. The lookups below and the query cache return active entities only.
Returns
Section titled “Returns”ReadonlySet<Entity>
on<
T>(token,handler): () =>void
Defined in: Scene.ts:644
Subscribe to scene-level events. Handlers fire for both:
- bubbled events from any entity (via
entity.emit) —entityis the source - scene-emitted events (via
scene.emit) —entityisundefined
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”EventToken<T>
handler
Section titled “handler”(data, entity?) => void
Returns
Section titled “Returns”() => void
onEnter()?
Section titled “onEnter()?”
optionalonEnter():void
Defined in: Scene.ts:726
Called when the scene is entered (after preload completes).
Returns
Section titled “Returns”void
onExit()?
Section titled “onExit()?”
optionalonExit():void
Defined in: Scene.ts:729
Called when the scene is exited (popped or replaced).
Returns
Section titled “Returns”void
onPause()?
Section titled “onPause()?”
optionalonPause():void
Defined in: Scene.ts:737
Called when the scene becomes effectively paused (isPaused flips to
true), whatever the source: a pauseBelow scene pushed on top, a manual
paused = true, the manager’s blur auto-pause, or a snapshot restoring
the scene paused.
Returns
Section titled “Returns”void
onProgress()?
Section titled “onProgress()?”
optionalonProgress(ratio):void
Defined in: Scene.ts:723
Called during asset preloading with progress ratio (0→1).
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
onResume()?
Section titled “onResume()?”
optionalonResume():void
Defined in: Scene.ts:744
Called when the scene stops being effectively paused (isPaused flips
to false): the scene above is popped, paused is cleared, or focus
returns after a blur auto-pause.
Returns
Section titled “Returns”void
registerScoped()
Section titled “registerScoped()”registerScoped<
T>(key,value):void
Defined in: Scene.ts:763
Register a scene-scoped service. Plugins call this from their
beforeEnter hook to expose per-scene state (render tree, physics
world, …) resolvable via Component.use(key). Game code can also use
it to attach scene-local services without needing a plugin.
Auto-cleared on scene exit — every key registered here is unregistered
after onExit runs (and after plugin afterExit hooks see them).
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”ServiceKey<T>
T
Returns
Section titled “Returns”void
serialize()?
Section titled “serialize()?”
optionalserialize():unknown
Defined in: Scene.ts:747
Return a JSON-serializable snapshot of this scene’s custom state. Used by the save system.
Returns
Section titled “Returns”unknown
service()
Section titled “service()”
protectedservice<T>(key):T
Defined in: Scene.ts:359
Lazy proxy-based service resolution. Can be used at field-declaration time:
readonly layers = this.service(RenderLayerManagerKey);The actual resolution is deferred until first property access and is
scope-aware (see use()). For scene-scoped keys, prefer resolving inside
onEnter() via use() rather than a field initializer — the proxy
caches the first resolved value, which would go stale if the scene is
exited and re-entered (the scoped value is recreated each enter).
Type Parameters
Section titled “Type Parameters”T extends object
Parameters
Section titled “Parameters”ServiceKey<T>
Returns
Section titled “Returns”T
spawn()
Section titled “spawn()”Call Signature
Section titled “Call Signature”spawn(
name?,options?):Entity
Defined in: Scene.ts:401
Spawn a new entity in this scene.
Pass { key } in the trailing options to register a stable per-scene
identity key, looked up later via scene.findByKey. The key is assigned
before setup() runs, so entity.requireKey() is safe inside it.
For the class form, the params type is inferred from the entity’s
setup(params) signature. Omitting a required field reports that field as
missing on the params object, naming the field that’s actually absent.
Runtime routing for the 2-arg class form (spawn(Class, X)):
- If the class doesn’t declare
setup→Xis options. - Else if
X’s own keys are exactly SpawnOptions fields ({ key }) →Xis options. Covers bothsetup(params = {})keyed without params andsetup()(no real params) keyed. - Else →
Xis params (forwarded tosetup). The 3-arg form is always unambiguous:spawn(Class, params, options). Ifsetup()throws, the entity is destroyed and removed before the error is rethrown.
Don’t name a top-level setup-params field key — the shape check would
misroute it. If you must, use the 3-arg form.
Parameters
Section titled “Parameters”string
options?
Section titled “options?”Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”spawn<
P>(blueprint,params,options?):Entity
Defined in: Scene.ts:408
Spawn from a blueprint. Note: blueprint params must not include a
top-level key: string field — the runtime can’t disambiguate it from
SpawnOptions. If your params do, use the explicit 3-arg form
(spawn(bp, params, { key })) so options arrives in the trailing slot.
Type Parameters
Section titled “Type Parameters”P
Parameters
Section titled “Parameters”blueprint
Section titled “blueprint”Blueprint<P>
params
Section titled “params”P
options?
Section titled “options?”Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”spawn(
blueprint,options?):Entity
Defined in: Scene.ts:409
Spawn a new entity in this scene.
Pass { key } in the trailing options to register a stable per-scene
identity key, looked up later via scene.findByKey. The key is assigned
before setup() runs, so entity.requireKey() is safe inside it.
For the class form, the params type is inferred from the entity’s
setup(params) signature. Omitting a required field reports that field as
missing on the params object, naming the field that’s actually absent.
Runtime routing for the 2-arg class form (spawn(Class, X)):
- If the class doesn’t declare
setup→Xis options. - Else if
X’s own keys are exactly SpawnOptions fields ({ key }) →Xis options. Covers bothsetup(params = {})keyed without params andsetup()(no real params) keyed. - Else →
Xis params (forwarded tosetup). The 3-arg form is always unambiguous:spawn(Class, params, options). Ifsetup()throws, the entity is destroyed and removed before the error is rethrown.
Don’t name a top-level setup-params field key — the shape check would
misroute it. If you must, use the 3-arg form.
Parameters
Section titled “Parameters”blueprint
Section titled “blueprint”Blueprint<void>
options?
Section titled “options?”Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”spawn<
E>(Class, …rest):E
Defined in: Scene.ts:411
Spawn an entity subclass; trailing args follow its setup() signature.
Type Parameters
Section titled “Type Parameters”E extends Entity
Parameters
Section titled “Parameters”() => E
…ClassSpawnArgs<E>
Returns
Section titled “Returns”E
tryResolveScoped()
Section titled “tryResolveScoped()”tryResolveScoped<
T>(key):T|undefined
Defined in: Scene.ts:793
Resolve a scene-scoped service registered via registerScoped, or
undefined if none is registered for this scene. Unlike use(), never
falls back to engine scope and never throws — the read for systems that
iterate scenes (e.g. physics and particles resolving SceneTimeKey).
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”ServiceKey<T>
Returns
Section titled “Returns”T | undefined
protecteduse<T>(key):T
Defined in: Scene.ts:316
Resolve a service by key. Scene-scoped values (registered via
registerScoped — e.g. the renderer’s per-scene render tree) take
precedence over engine scope, so the obvious call works in the obvious
place:
onEnter() { const tree = this.use(SceneRenderTreeKey); // resolvable from onEnter on tree.fx.addEffect(crt());}Scene-scoped values are registered by plugin beforeEnter hooks, which
run before onEnter, so they’re available throughout the scene’s
lifecycle. Throws if the key resolves nowhere. For lazy resolution at
field-declaration time, use service().
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”ServiceKey<T>
Returns
Section titled “Returns”T