SceneInstance

View source

Associates an ECS entity with a scene asset to instantiate beneath that entity.

The component stores a live Handle for a Scene asset and may store a second handle for a SceneFilter asset. The scene is restored beneath the component’s entity when its asset is available. An optional SceneFilter limits which component and resource types are restored.

ScenePlugin provides scene instantiation support. The component’s entity remains the root of the restored scene.

Examples

import { World } from '@wimaengine/ecs'
import { SceneInstance } from '@wimaengine/scene'

// `sceneHandle` is a Handle<Scene> from the scene asset pool or asset server.
const sceneHandle = getSceneHandle()
const world = new World()
const instanceEntity = world.spawn([
  new SceneInstance(sceneHandle)
])

// The scene is instantiated beneath instanceEntity when its asset is ready.
const instance = world.get(instanceEntity, SceneInstance)
console.log(instance?.entityMap.size ?? 0)

Constructor


constructor(handle: Handle<Scene>, filter?: Handle<SceneFilter>)

View source

Creates a component that references a scene asset and, optionally, a filter asset.

The supplied handles are stored directly. This constructor does not clone them or acquire replacement references.

Parameters

NameDescriptionDefault
handle——
filter?

Optional filter asset handle.

—

Properties


entityMap: Map<number, number>

View source

Maps each restored world entity to its source scene entity.

Both keys and values are packed entity IDs. The map is empty until the scene is restored, is rebuilt for later restorations, and is not included in the component’s snapshot.

Default: ...

handle: Handle<Scene>

View source

Live handle for the scene asset to restore.

The constructor stores the supplied handle directly. copy() and clone() create independent references to the same asset; scene support releases the reference when the component is removed.

filter: Handle<SceneFilter>

View source

Optional live handle for a scene component and resource filter.

The filter limits which component and resource types are restored. An undefined value means that no filter is applied.

Methods


staticcopy(source: SceneInstance, target?: SceneInstance): SceneInstance

View source

Copies a scene instance with independent asset-handle references.

Both live handles are cloned. A supplied target keeps its existing entityMap; the default target starts with a new empty map and never copies the source’s runtime mapping.

Parameters

NameDescriptionDefault
source——
target?—...

Returns

The populated target component.

staticclone(target: SceneInstance): SceneInstance

View source

Creates a scene instance with cloned asset-handle references.

The returned component has a fresh runtime entityMap and does not share the source’s map.

Parameters

NameDescriptionDefault
target——

statictoSnapshot(instance: SceneInstance, world: World): SceneInstanceSnapshot

View source

Creates a persistence snapshot for this scene instance.

The scene handle and optional filter handle are converted to HandleSnapshot values. The returned snapshot contains no live handles and does not include entityMap; the mapping is rebuilt when the scene is restored. Numeric, scene-local asset references require the owning scene asset ID when restored.

Parameters

NameDescriptionDefault
instance

Live scene instance being snapshotted.

—
world

World used to resolve asset metadata.

—

Returns

Snapshot of the live asset handles.