Examples
// ScenePlugin installs refreshModifiedScenes in Update/CoreSystems.End.
app.registerPlugin(new ScenePlugin())
// A SceneModified event removes old descendants and queues each live root;
// spawnScenes then restores the current scene asset.Function
refreshModifiedScenes(world: World): voidRefreshes live scene instances after their scene asset is modified.
ScenePlugin registers this function directly in the repeating
AppSchedule.Update schedule’s
CoreSystems.End group.
It runs after the SceneModified event buffer is cleared and before the spawnScenes system. It reads the typed Events resource for SceneModified events and matches each event’s asset id
against live SceneInstance components through a Query.
The query returns the instance entity, its SceneInstance, and an
optional Children component. Matching uses the live handle’s exact
instance.handle.id(). The instance entity itself remains alive; when
Children is present, the system despawns every direct child in reverse
list order. Each World#despawn call lets hierarchy
hooks remove that child’s descendants as well as the child from the
parent’s live list while the loop is traversing it. Instances without
Children skip that loop.
After descendants are removed, the system calls SceneSpawner#add
with the modified scene id and instance entity. This queues the instance for
restoration; it does not spawn immediately. The add is idempotent for the
same scene id and entity, and every live instance matching the modified id
is queued. The later spawnScenes pass restores the available asset
beneath those queued roots in the same update’s scene-system flow.
Events#each iterates the current readable
SceneModified batch in write order but does not clear or remove events.
This function never calls Events#clear; the event plugin’s
separately scheduled clear system performs that buffer rotation before this
system runs. Events written after that clear wait for a later published
batch.
// ScenePlugin installs refreshModifiedScenes in Update/CoreSystems.End.
app.registerPlugin(new ScenePlugin())
// A SceneModified event removes old descendants and queues each live root;
// spawnScenes then restores the current scene asset.