# Entity

In typed-ecstasy, entities are simple bags of components grouped under a unique ID. All non zero entity IDs are considered valid.

# Creating and Adding an Entity

If you want to create an Entity, you need to ask your Engine for a new instance.

const entity = new Entity();

Alternatively, you can assemble entities based on blueprints using a data-driven approach:

const entity = factory.assemble("car");

Entities need to be explicitly added to the engine so as to be processed by systems:

engine.entities.add(entity);

The reason this is divided into two steps is to allow you to add all of your components to the entity before actually adding it to the engine.

Removing entities from the engine is rather simple. Calling engine.entities.remove() or entity.destroy() frees the entity (possibly delayed).

engine.entities.remove(entity); // or entity.destroy();

# Entity IDs

As said, each entity has a unique ID. You can get it using entity.getId(), which returns a number. Entities will have an invalid ID (0) until they're added to an engine.

Entities can be retrieved from the engine using their ID:

const entity = engine.getEntity(id);