Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Entities

Eric McDaniel edited this page Sep 10, 2021 · 12 revisions

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].

Creating and Destroying Entities

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)

Setting and Un-setting Components

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)
Clone this wiki locally