-
Notifications
You must be signed in to change notification settings - Fork 1
Entities
Entities in Harmony are fully defined by their component makeup. They are integers that act as "pointers" to a specific row in an archetype table.
The component makeup of an entity is called its type. A type is an array of schema ids (integers) that identifies the component signature of an entity. For example, if your program had Health
(1), Transform
(4), and Velocity
(9) schemas, an entity with that exact set of components would have a type of [1,4,9]
.
An entity is created using the makeEntity
function, which requires a world and a type:
const entity = makeEntity(world, [Health])
The variable entity
in the above example holds an integer value that references a row of components in a table. Component data will automatically be created for the entity using the provided type.
Initial values for component data can be provided using a third argument to makeEntity
:
makeEntity(world, [Health], 100)
makeEntity(world, [Position, Velocity], [{ x: 0, y: 0 }, { x: 0, y: 0 }])
To destroy an entity, call destroyEntity
with an entity pointer:
destroyEntity(entity)
A component can be assigned to an entity using set
:
set(world, entity, Faction, 15)
A component can be removed from an entity using unset
:
unset(world, entity, Faction)