LoadingScene
Defined in: LoadingScene.ts:46
Base class for a progress-bar style loading screen.
Preloads the target scene’s assets through the AssetManager, exposes
progress and emits scene:loading:progress / scene:loading:done on
the engine event bus, enforces minDuration to prevent flicker on cached
loads, then replaces itself with target — optionally through a
transition.
LoadingScene owns orchestration only. It does not render anything. To show
a progress UI, spawn an entity that subscribes to the loading events (the
canonical default is LoadingSceneProgressBar in @yagejs/ui, or any
custom component). The loading scene is a normal Scene, so you can use
onEnter to spawn whatever you want.
class Boot extends LoadingScene { readonly target = new GameScene(); readonly minDuration = 0.5; readonly transition = fade({ duration: 0.3 }); override onEnter() { this.spawn(LoadingSceneProgressBar); this.startLoading(); }}
await engine.scenes.replace(new Boot());Set autoContinue = false to gate the handoff behind a continue() call
— useful for “press any key to continue” flows. scene:loading:done
still fires so UI can react (show a prompt), and whoever eventually
calls this.continue() triggers the transition.
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new LoadingScene():
LoadingScene
Returns
Section titled “Returns”LoadingScene
Inherited from
Section titled “Inherited from”Properties
Section titled “Properties”_childSpawn
Section titled “_childSpawn”_childSpawn:
boolean=false
Defined in: Scene.ts:315
Internal
Set by Entity.spawnChild for the duration of its spawn call, and
consumed by that call. It marks the one spawn a child creation is allowed
to make while a batch is open; anything else reaching spawn then is a
top-level entity the batch could not roll back.
Inherited from
Section titled “Inherited from”_spawnInert
Section titled “_spawnInert”_spawnInert:
boolean=false
Defined in: Scene.ts:306
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.
Inherited from
Section titled “Inherited from”autoContinue
Section titled “autoContinue”
readonlyautoContinue:boolean=true
Defined in: LoadingScene.ts:71
When true (default), the handoff fires automatically after loading and
minDuration. Set false to gate it behind continue() — useful when
the loading scene also asks the player to press a key or click.
defaultTransition?
Section titled “defaultTransition?”
readonlyoptionaldefaultTransition?:SceneTransition
Defined in: Scene.ts:204
Default transition used when this scene is the destination of a push/pop/replace.
Inherited from
Section titled “Inherited from”fixedUpdate?
Section titled “fixedUpdate?”
readonlyoptionalfixedUpdate?:undefined
Defined in: Scene.ts:1018
Reserved: a subclass that declares fixedUpdate fails to compile.
There is no fixed-step scene hook either, and for the same reason. Both
homes above apply: a component on an entity the scene spawns, or a
process on the queue that makeSceneScopedQueue() returns.
The slot is optional, so the compiler reports the subclass method as not
assignable to type undefined rather than to type never.
Inherited from
Section titled “Inherited from”minDuration
Section titled “minDuration”
readonlyminDuration:number=0
Defined in: LoadingScene.ts:61
Minimum wall-clock seconds the scene stays visible before handing off. Prevents flicker on cached loads. Default 0.
readonlyname:string="loading"
Defined in: LoadingScene.ts:47
Name for debugging/inspection.
Overrides
Section titled “Overrides”pauseBelow
Section titled “pauseBelow”
readonlypauseBelow:boolean=true
Defined in: Scene.ts:182
Whether scenes below this one in the stack should be paused. Default: true.
Inherited from
Section titled “Inherited from”preload?
Section titled “preload?”
readonlyoptionalpreload?: readonlyAssetHandle<unknown>[]
Defined in: Scene.ts:201
Asset handles to load before onEnter(). Override in subclasses.
Inherited from
Section titled “Inherited from”target
Section titled “target”Defined in: LoadingScene.ts:55
Scene to load and transition to. Accepts an instance or a factory —
use a factory when target construction should be deferred until
loading starts (heavy constructors, side effects). The factory runs
before the preload so target.preload can be inspected.
timeScale
Section titled “timeScale”timeScale:
number=1
Defined in: Scene.ts:276
Time scale multiplier for this scene. 1.0 = normal, 0.5 = half speed. Default: 1.
Inherited from
Section titled “Inherited from”transition?
Section titled “transition?”
readonlyoptionaltransition?:SceneTransition
Defined in: LoadingScene.ts:64
Transition used for the loading → target handoff.
transparentBelow
Section titled “transparentBelow”
readonlytransparentBelow:boolean=false
Defined in: Scene.ts:198
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.
Inherited from
Section titled “Inherited from”update?
Section titled “update?”
readonlyoptionalupdate?:undefined
Defined in: Scene.ts:1006
Reserved: a subclass that declares update fails to compile.
The engine’s per-frame pass ticks components, so a scene method with this
name is dead code. Per-frame scene logic has two homes: a component on an
entity the scene spawns, or a process on the queue that
makeSceneScopedQueue() returns, which lives and dies with the scene.
The slot is optional, so the compiler reports the subclass method as not
assignable to type undefined rather than to type never.
The hooks above are every hook Scene itself declares; LoadingScene
adds onLoadError for a preload that fails.
Inherited from
Section titled “Inherited from”Accessors
Section titled “Accessors”assets
Section titled “assets”Get Signature
Section titled “Get Signature”get assets():
AssetManager
Defined in: Scene.ts:346
Convenience accessor for the AssetManager.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”context
Section titled “context”Get Signature
Section titled “Get Signature”get context():
EngineContext
Defined in: Scene.ts:321
Access the EngineContext.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”isPaused
Section titled “isPaused”Get Signature
Section titled “Get Signature”get isPaused():
boolean
Defined in: Scene.ts:326
Whether this scene is effectively paused (manual pause or paused by stack).
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”isTransitioning
Section titled “isTransitioning”Get Signature
Section titled “Get Signature”get isTransitioning():
boolean
Defined in: Scene.ts:340
Whether a scene transition is currently running.
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”paused
Section titled “paused”Get Signature
Section titled “Get Signature”get paused():
boolean
Defined in: Scene.ts:220
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:224
Parameters
Section titled “Parameters”boolean
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”progress
Section titled “progress”Get Signature
Section titled “Get Signature”get progress():
number
Defined in: LoadingScene.ts:103
Current load progress, 0 → 1. Updated as the AssetManager reports progress.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”_addExistingEntity()
Section titled “_addExistingEntity()”_addExistingEntity(
entity):void
Defined in: Scene.ts:786
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
Inherited from
Section titled “Inherited from”_announceBatchEntity()
Section titled “_announceBatchEntity()”_announceBatchEntity(
entity):void
Defined in: Scene.ts:742
Internal
Internal: announce one committed batch entity. The entity is dormant, so
component:added joins no query — activation does that.
Parameters
Section titled “Parameters”entity
Section titled “entity”Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_assertKeyFree()
Section titled “_assertKeyFree()”_assertKeyFree(
key):void
Defined in: Scene.ts:711
Internal
Internal: throw if a live entity already holds key. A spawn batch checks
it when reserving, long before the key reaches the index.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_clearScopedServices()
Section titled “_clearScopedServices()”_clearScopedServices():
void
Defined in: Scene.ts:1085
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
Inherited from
Section titled “Inherited from”_destroyAllEntities()
Section titled “_destroyAllEntities()”_destroyAllEntities():
void
Defined in: Scene.ts:1174
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
Inherited from
Section titled “Inherited from”_dropFromDestroyQueue()
Section titled “_dropFromDestroyQueue()”_dropFromDestroyQueue(
entities):void
Defined in: Scene.ts:758
Internal
Internal: drop entities a spawn batch discarded from the destroy queue. They are already fully torn down, and the end-of-frame flush would run their teardown a second time.
Parameters
Section titled “Parameters”entities
Section titled “entities”ReadonlySet<Entity>
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_finalizeEntityDestroy()
Section titled “_finalizeEntityDestroy()”_finalizeEntityDestroy(
entity,announce?,onError?):void
Defined in: Scene.ts:1144
Internal
Internal: tear an entity down and take it out of the scene.
A spawn batch rolling back passes announce: false for entities it never
published, and an onError handler: its teardown has to finish whatever
throws, because the error the caller is waiting for is the one that
started the rollback.
Parameters
Section titled “Parameters”entity
Section titled “entity”announce?
Section titled “announce?”boolean = true
onError?
Section titled “onError?”(error) => void
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_flushDestroyQueue()
Section titled “_flushDestroyQueue()”_flushDestroyQueue():
void
Defined in: Scene.ts:1128
Internal
Flush the destroy queue — destroy pending entities. Called by the engine during the endOfFrame phase.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_observeTokenEvent()
Section titled “_observeTokenEvent()”_observeTokenEvent(
eventName,data,entity):void
Defined in: Scene.ts:947
Internal
Observe a token event after its handlers ran: an entity emit after it
dispatched locally and bubbled here (entity is the source), or a
scene.emit (entity is undefined). Tooling only; game code should
keep using on(). The observer is a callback dispatched outside any
wrapped tick, so a throw is attributed here.
Parameters
Section titled “Parameters”eventName
Section titled “eventName”string
unknown
entity
Section titled “entity”Entity | undefined
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_onEntityEvent()
Section titled “_onEntityEvent()”_onEntityEvent(
eventName,data,entity):void
Defined in: Scene.ts:919
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
Inherited from
Section titled “Inherited from”_queueDestroy()
Section titled “_queueDestroy()”_queueDestroy(
entity):void
Defined in: Scene.ts:820
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
Inherited from
Section titled “Inherited from”_registerBatchEntities()
Section titled “_registerBatchEntities()”_registerBatchEntities(
entities):void
Defined in: Scene.ts:727
Internal
Internal: put a committed batch’s entities in the scene. Keys land here
too, so the first entity:created subscriber can already find any of
them by key.
Parameters
Section titled “Parameters”entities
Section titled “entities”readonly Entity[]
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_registerKey()
Section titled “_registerKey()”_registerKey(
entity,key):void
Defined in: Scene.ts:700
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
Inherited from
Section titled “Inherited from”_registerPool()
Section titled “_registerPool()”_registerPool(
pool):void
Defined in: Scene.ts:770
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
Inherited from
Section titled “Inherited from”_registerScoped()
Section titled “_registerScoped()”_registerScoped<
T>(key,value):void
Defined in: Scene.ts:1042
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
Inherited from
Section titled “Inherited from”_reinsert()
Section titled “_reinsert()”_reinsert(
entity):void
Defined in: Scene.ts:810
Internal
Move entity and its descendants to the end of the entity set, so a
pass already iterating the set visits them after the entity that
acquired them — the position a fresh spawn gets.
Parameters
Section titled “Parameters”entity
Section titled “entity”Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_resolveScoped()
Section titled “_resolveScoped()”_resolveScoped<
T>(key):T|undefined
Defined in: Scene.ts:1076
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
Inherited from
Section titled “Inherited from”_setContext()
Section titled “_setContext()”_setContext(
context):void
Defined in: Scene.ts:1093
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
Inherited from
Section titled “Inherited from”_setTokenEventObserver()
Section titled “_setTokenEventObserver()”_setTokenEventObserver(
observer?):void
Defined in: Scene.ts:1051
Internal
Install or clear a tooling-only observer for token events — bubbled
entity emits and scene.emit alike.
Parameters
Section titled “Parameters”observer?
Section titled “observer?”(eventName, data, entity) => void
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”_unregisterPool()
Section titled “_unregisterPool()”_unregisterPool(
pool):void
Defined in: Scene.ts:778
Internal
Internal: stop tracking a pool. Called by EntityPool.dispose.
Parameters
Section titled “Parameters”ScenePool
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”continue()
Section titled “continue()”continue():
void
Defined in: LoadingScene.ts:149
Trigger the handoff to target. No-op if already called or if
autoContinue already fired it. If called before loading finishes,
the handoff runs as soon as loading + minDuration complete.
Returns
Section titled “Returns”void
emit()
Section titled “emit()”Call Signature
Section titled “Call Signature”emit(
token):void
Defined in: Scene.ts:892
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
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”emit<
T>(token,data):void
Defined in: Scene.ts:893
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
Inherited from
Section titled “Inherited from”findByKey()
Section titled “findByKey()”findByKey<
E>(key):E|undefined
Defined in: Scene.ts:688
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
Inherited from
Section titled “Inherited from”findEntities()
Section titled “findEntities()”Call Signature
Section titled “Call Signature”findEntities<
T>(filter):Entity&T[]
Defined in: Scene.ts:850
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[]
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”findEntities(
filter?):Entity[]
Defined in: Scene.ts:853
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[]
Inherited from
Section titled “Inherited from”findEntitiesByTag()
Section titled “findEntitiesByTag()”findEntitiesByTag(
tag):Entity[]
Defined in: Scene.ts:841
Find active entities by tag.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Entity[]
Inherited from
Section titled “Inherited from”findEntity()
Section titled “findEntity()”findEntity(
name):Entity|undefined
Defined in: Scene.ts:833
Find an active entity by name (first match).
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Entity | undefined
Inherited from
Section titled “Inherited from”getEntities()
Section titled “getEntities()”getEntities():
ReadonlySet<Entity>
Defined in: Scene.ts:828
Every entity in the scene, dormant ones included. Teardown walks this set; the lookups below and the query cache return active entities only.
Returns
Section titled “Returns”ReadonlySet<Entity>
Inherited from
Section titled “Inherited from”on<
T>(token,handler): () =>void
Defined in: Scene.ts:870
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
Inherited from
Section titled “Inherited from”onEnter()?
Section titled “onEnter()?”
optionalonEnter():void
Defined in: Scene.ts:973
Called when the scene is entered (after preload completes).
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”onExit()
Section titled “onExit()”onExit():
void
Defined in: LoadingScene.ts:155
Called when the scene is exited (popped or replaced).
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”onLoadError()?
Section titled “onLoadError()?”
optionalonLoadError(error):void|Promise<void>
Defined in: LoadingScene.ts:86
Optional hook; fires if asset loading rejects. The scene stays mounted
whether or not this is set. When set, the hook is the recovery channel:
draw a retry UI, push an error scene, or call this.startLoading()
again to retry the load. When unset, the error is logged via the engine
logger and the scene remains mounted in a failed state with no
automatic recovery.
The hook may still be running when the scene is replaced externally —
don’t assume the scene is live (check this.context.tryResolve rather
than this.service before touching engine services, and avoid spawning
new entities after an await).
Parameters
Section titled “Parameters”Error
Returns
Section titled “Returns”void | Promise<void>
onPause()?
Section titled “onPause()?”
optionalonPause():void
Defined in: Scene.ts:983
Called when the scene becomes effectively paused (isPaused flips to
true), whatever the source: a pauseBelow scene pushed on top, a manual
paused = true, or the manager’s blur auto-pause.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”onProgress()?
Section titled “onProgress()?”
optionalonProgress(ratio):void
Defined in: Scene.ts:970
Called during asset preloading with progress ratio (0→1).
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”onResume()?
Section titled “onResume()?”
optionalonResume():void
Defined in: Scene.ts:990
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
Inherited from
Section titled “Inherited from”registerScoped()
Section titled “registerScoped()”registerScoped<
T>(key,value):void
Defined in: Scene.ts:1032
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). It is not for game
state: score, lives or a run timer live in a component on a host entity
spawned with a key and found with findByKey.
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
Inherited from
Section titled “Inherited from”service()
Section titled “service()”service<
T>(key):T
Defined in: Scene.ts:429
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
Inherited from
Section titled “Inherited from”spawn()
Section titled “spawn()”Call Signature
Section titled “Call Signature”spawn(
name?,options?):Entity
Defined in: Scene.ts:471
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 error reaches the caller unchanged and the entity stays in the scene with whatever setup had added so far.
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”Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”spawn<
P>(blueprint,params,options?):Entity
Defined in: Scene.ts:478
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”Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”spawn(
blueprint,options?):Entity
Defined in: Scene.ts:479
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 error reaches the caller unchanged and the entity stays in the scene with whatever setup had added so far.
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”Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”spawn<
E>(Class, …rest):E
Defined in: Scene.ts:481
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
Inherited from
Section titled “Inherited from”spawnBatch()
Section titled “spawnBatch()”spawnBatch<
T>(build):T
Defined in: Scene.ts:657
Build a set of entities that all exist before any of them is set up, and that arrive in the scene together or not at all.
spawn() finishes one entity at a time, so the second entity does not
exist while the first runs setup(), and a failure halfway leaves the
entities before it in the scene. A batch reserves every entity first, so
setup parameters can carry handles in any direction, and a throw anywhere
— in setup(), in a lifecycle-event subscriber, in an onEnable hook —
discards the whole set synchronously and publishes nothing.
const { turret, target } = scene.spawnBatch((batch) => { const turret = batch.reserve(Turret, { key: "level/turret" }); const target = batch.reserve(Dummy, { key: "level/dummy" }); batch.setup(turret, { aimAt: target.handle() }); batch.setup(target); return { turret, target };});The callback returns whatever the caller needs; spawnBatch returns it
once the batch commits. Reserved entities stay out of
scene.getEntities(), findByKey(), and every query until then, so
nothing running in the scene can observe a half-built set. entity:created
and component:added publish afterwards, in reservation order.
Inside the callback, entity.spawnChild() joins the batch and is rolled
back with it. A top-level scene.spawn() throws instead — a batch cannot
roll back an entity it does not own.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”(batch) => T
Returns
Section titled “Returns”T
Inherited from
Section titled “Inherited from”startLoading()
Section titled “startLoading()”startLoading():
void
Defined in: LoadingScene.ts:124
Kick off asset loading. While a load is in flight, subsequent calls
are no-ops. After a load failure the guard is released, so calling
startLoading() from onLoadError (or from a retry button) kicks off
a fresh load against the same target.
Usually called once from onEnter after spawning the loading UI:
override onEnter() { this.spawn(LoadingSceneProgressBar); this.startLoading();}Deferring the call lets you gate the start of the load behind a title screen, “press any key” prompt, intro animation, etc.
Returns
Section titled “Returns”void
tryResolveScoped()
Section titled “tryResolveScoped()”tryResolveScoped<
T>(key):T|undefined
Defined in: Scene.ts:1067
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
Inherited from
Section titled “Inherited from”use<
T>(key):T
Defined in: Scene.ts:374
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. Callable from the scene itself and from anything holding a scene
reference — an entity’s setup(), a helper function, an addon:
class LevelScene extends Scene { onEnter() { this.use(SceneRenderTreeKey).fx.addEffect(crt()); }}
class Torch extends Entity { setup() { const lighting = this.scene.use(LightingWorldKey); }}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
Inherited from
Section titled “Inherited from”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.