API reference

Every public class, method, and event in @codexo/exojs. Generated from source.

C

classPrefab

@codexo/exojs / core / stable

A reusable, data-driven template captured from a configured scene-graph subtree. Capture once with Prefab.from; stamp out independent copies with instantiate as many times as needed - no re-serialization per instance. A prefab holds the same **data, not behaviour** a scene serializer captures (structure, transforms, visuals, asset references). Re-attach behaviour (signal handlers, systems) in code after instantiate. ```ts const coin = Prefab.from(buildCoin(), loader); for (let i = 0; i < 10; i++) { const node = coin.instantiate(loader); node.setPosition(i * 32, 0); scene.addChild(node); } ```

0
props
4
methods
0
events
Import
import { Prefab } from '@codexo/exojs'

A reusable, data-driven template captured from a configured scene-graph subtree. Capture once with Prefab.from; stamp out independent copies with instantiate as many times as needed - no re-serialization per instance.

A prefab holds the same **data, not behaviour** a scene serializer captures (structure, transforms, visuals, asset references). Re-attach behaviour (signal handlers, systems) in code after instantiate.

```ts const coin = Prefab.from(buildCoin(), loader); for (let i = 0; i < 10; i++) { const node = coin.instantiate(loader); node.setPosition(i * 32, 0); scene.addChild(node); } ```

Methods4
Instantiate a fresh, independent copy of the captured subtree. Referenced assets must be pre-loaded into loader. Call repeatedly for many instances. Pass app.serializers as registry to resolve app-scoped (extension) serializers; defaults to the global registry.
The prefab as a versioned, JSON-serialisable document - the standard JSON.stringify(prefab) hook. Treat the returned object as read-only; the root is the live internal descriptor, not a copy.
Capture node's subtree as a prefab. Pass the Loader so texture and other asset references resolve to their source keys. Pass app.serializers as registry to resolve app-scoped (extension) serializers; defaults to the global registry.
fromJSON(document: unknown): Prefab
Build a prefab from a previously serialized document - e.g. one produced by toJSON and persisted to disk or fetched over the network. Like Scene.deserialize this is an untrusted boundary, so the parameter is unknown: the document's version frame and root node are validated here. Throws when the document is not an object, carries a version newer than this build supports, or has no valid root.
Source