Flecs v3.2
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
Adding & Removing

Functions for adding and removing components. More...

Functions

void ecs_add_id (ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
 Add a (component) id to an entity. More...
 
void ecs_remove_id (ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
 Remove a (component) id from an entity. More...
 
void ecs_override_id (ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
 Add override for (component) id. More...
 
void ecs_clear (ecs_world_t *world, ecs_entity_t entity)
 Clear all components. More...
 
void ecs_remove_all (ecs_world_t *world, ecs_id_t id)
 Remove all instances of the specified (component) id. More...
 
ecs_entity_t ecs_set_with (ecs_world_t *world, ecs_id_t id)
 Set current with id. More...
 
ecs_id_t ecs_get_with (const ecs_world_t *world)
 Get current with id. More...
 

Detailed Description

Functions for adding and removing components.

Function Documentation

◆ ecs_add_id()

void ecs_add_id ( ecs_world_t world,
ecs_entity_t  entity,
ecs_id_t  id 
)

Add a (component) id to an entity.

This operation adds a single (component) id to an entity. If the entity already has the id, this operation will have no side effects.

Parameters
worldThe world.
entityThe entity.
idThe id to add.

◆ ecs_clear()

void ecs_clear ( ecs_world_t world,
ecs_entity_t  entity 
)

Clear all components.

This operation will remove all components from an entity.

Parameters
worldThe world.
entityThe entity.

◆ ecs_get_with()

ecs_id_t ecs_get_with ( const ecs_world_t world)

Get current with id.

Get the id set with ecs_set_with.

Parameters
worldThe world.
Returns
The last id provided to ecs_set_with.

◆ ecs_override_id()

void ecs_override_id ( ecs_world_t world,
ecs_entity_t  entity,
ecs_id_t  id 
)

Add override for (component) id.

Adding an override to an entity ensures that when the entity is instantiated (by adding an IsA relationship to it) the component with the override is copied to a component that is private to the instance. By default components reachable through an IsA relationship are shared.

Adding an override does not add the component. If an override is added to an entity that does not have the component, it will still be added to the instance, but with an uninitialized value (unless the component has a ctor). When the entity does have the entity, the component of the instance will be initialized with the value of the component on the entity.

This is the same as what happens when calling ecs_add_id for an id that is inherited (reachable through an IsA relationship).

This operation is equivalent to doing: ecs_add_id(world, entity, ECS_OVERRIDE | id);

Parameters
worldThe world.
entityThe entity.
idThe id to override.

◆ ecs_remove_all()

void ecs_remove_all ( ecs_world_t world,
ecs_id_t  id 
)

Remove all instances of the specified (component) id.

This will remove the specified id from all entities (tables). The id may be a wildcard and/or a pair.

Parameters
worldThe world.
idThe id.

◆ ecs_remove_id()

void ecs_remove_id ( ecs_world_t world,
ecs_entity_t  entity,
ecs_id_t  id 
)

Remove a (component) id from an entity.

This operation removes a single (component) id to an entity. If the entity does not have the id, this operation will have no side effects.

Parameters
worldThe world.
entityThe entity.
idThe id to remove.

◆ ecs_set_with()

ecs_entity_t ecs_set_with ( ecs_world_t world,
ecs_id_t  id 
)

Set current with id.

New entities are automatically created with the specified id.

Parameters
worldThe world.
idThe id.
Returns
The previous id.