Scene
world.Scene(idOrName) ⇒ Promise<U.Group | null>
Loads another Unia project into the current scene using its project ID or name.
const scene = await world.Scene('occlusion')
if (scene) {
scene.position.set(10, 0, 0)
scene.sync()
}
// A project ID can also be used.
const sceneByID = await world.Scene(
'c271d812-f748-4c2d-bc96-732092ffbba8'
)
The returned U.Group is the root of the imported scene. Its name comes from
the imported project's name when available. The imported project's top-level
objects are children of this group, so moving, rotating, scaling, or hiding the
group affects the whole imported scene. Call sync() after changing its
transform.
The imported project's assets and geometry are loaded automatically. If the current scene is playing, its scripts are also initialized using the imported project's own script and asset context. A scene loaded before Play starts is initialized when Play starts.
Script scope
Top-level let, const, and var declarations in attached scripts are local
to each script execution. Local imported modules are also resolved separately
for each scene, so identically named scripts and variables in different scenes
do not collide. Browser globals such as window.value and globalThis.value,
and properties added to the shared world singleton, are shared by every scene
and can collide. Prefer local modules for scene-specific shared state.
world.db is scoped to the script's source project, including local imports,
async callbacks, and world.attachScript() calls. Imported scenes keep using
their source project's documents rather than the outer project's documents.
Multiple instances of the same source project share that database namespace.
Other world properties remain shared. See Database for write
permissions and the explicit outer-project access through window.world.db.
Names are resolved to their canonical project IDs before the scene is loaded.
Names must match exactly. world.Scene() returns null when no project data is
available. Other loading failures reject the promise. Always pass a project ID
or name and guard the result before using it.
let environment = null
this.init = async () => {
environment = await world.Scene('environment-name')
if (!environment) return
environment.position.set(0, 0, -20)
environment.sync()
}
Use world.remove(scene) to remove a runtime-loaded scene and its descendants.