Adds a component to an existing entity.
Dynamically adds a component at runtime. The entity will immediately match any queries that require this component. Uses Miniplex's reactive system.
The Strata world.
The entity to modify.
The component key to add.
The component value.
const entity = world.spawn({ position: { x: 0, y: 0, z: 0 } });// Add health component lateraddComponent(world, entity, 'health', 100);// Now entity matches queries for 'health'for (const e of world.query('health')) { console.log(e.health); // entity is included} Copy
const entity = world.spawn({ position: { x: 0, y: 0, z: 0 } });// Add health component lateraddComponent(world, entity, 'health', 100);// Now entity matches queries for 'health'for (const e of world.query('health')) { console.log(e.health); // entity is included}
Adds a component to an existing entity.
Dynamically adds a component at runtime. The entity will immediately match any queries that require this component. Uses Miniplex's reactive system.