Entities · function

instantiate

Make one.

Explained in Entities.

function instantiate(world: World, prefab: Prefab, overrides?: Readonly<Record<string, Readonly<Record<string, unknown>>>>): Entity
import { instantiate } from '@driftengine/entities';

Parameters

ParameterTypeDescription
worldWorld
prefabPrefab
overrides?Readonly<Record<string, Readonly<Record<string, unknown>>>>

In depth

Overrides are keyed by component name, because that is what a caller has in front of them — a ComponentType key would mean holding the type to override a field of it, which is exactly the import a scene file or an editor panel does not have.

An override naming a component the prefab does not carry is refused. Adding it instead would make a typo a silent extra component, and adding nothing would make a typo a silent no-op; the only answer that cannot be mistaken for working is to say so.