Spawning Objects
ObjectManagementSystem is the runtime factory the editor uses to create every built-in object kind. From inside a Behaviour you can ask it to spawn the same primitives at runtime — pre-wired with all of their default components.
ts
import { Behaviour, ObjectManagementSystem } from "@relu-interactives/spatial-ecs";
export default class Example extends Behaviour {
init() {
const objects = this.world.getSystem(ObjectManagementSystem);
objects?.requestCreate("cube", { name: "MyCube" }, (entityId) => {
console.log("spawned", entityId);
});
}
}The requestCreate payload
Every kind accepts the same envelope:
ts
objects.requestCreate(
kind, // one of the supported kinds below
payload, // common + kind-specific fields (see each page)
onCreated?, // optional callback (entityId) => void
);Common payload fields available on every kind:
| Field | Type | Description |
|---|---|---|
name | string | Display name. Defaults to a sensible label per kind (e.g. "Cube"). |
transform.position | { x, y, z } | World-space position. |
transform.rotation | { x, y, z } | Euler rotation in radians. |
transform.scale | { x, y, z } | Per-axis scale. Defaults to 1. |
parentId | EntityId | null | Attach the new entity under another entity. |
Kind-specific fields go on payload.path (asset URL) or payload.options (typed options bag). Each page below lists exactly what is read.
Use requestCreate (queued) vs createNow (immediate)
| Method | Returns | When to use |
|---|---|---|
requestCreate(kind, payload, onCreated?) | void (callback fires after creation) | Default. Schedules creation to run between frames so it never collides with other systems. |
createNow(kind, world, payload) | EntityId | When you need the id synchronously (rare). Skips the queue. |

