Flecs: Each iterator
Description: A fast entity component system (ECS) for C & C++

| Flecs v4.0 A fast entity component system (ECS) for C & C++

Loading...
Searching...
No Matches
Each iterator
C API » Core

Find all entities that have a single (component) id. More...

Collaboration diagram for Each iterator:

## Functions
ecs_iter_t | ecs_each_id (const ecs_world_t *world, ecs_id_t component)
| Iterate all entities with specified (component id).
bool | ecs_each_next (ecs_iter_t *it)
| Progress an iterator created with ecs_each_id().
ecs_iter_t | ecs_children (const ecs_world_t *world, ecs_entity_t parent)
| Iterate children of parent.
ecs_iter_t | ecs_children_w_rel (const ecs_world_t *world, ecs_entity_t relationship, ecs_entity_t parent)
| Same as ecs_children() but with custom relationship argument.
bool | ecs_children_next (ecs_iter_t *it)
| Progress an iterator created with ecs_children().

## Detailed Description

Find all entities that have a single (component) id.

## Function Documentation

## ◆ ecs_children()

ecs_iter_t ecs_children | ( | const ecs_world_t * | world,
|  | ecs_entity_t | parent )

Iterate children of parent.

This operation is usually equivalent to doing:

ecs_iter_t it = ecs_each_id(world, ecs_pair(EcsChildOf, parent));
EcsChildOf
const ecs_entity_t EcsChildOf
Used to express parent-child relationships.
ecs_each_id
ecs_iter_t ecs_each_id(const ecs_world_t *world, ecs_id_t component)
Iterate all entities with specified (component id).
ecs_iter_t
Iterator.
Definition flecs.h:1142

The only exception is when the parent has the EcsOrderedChildren trait, in which case this operation will return a single result with the ordered child entity ids.

This operation is equivalent to doing:

ecs_children_w_rel(world, EcsChildOf, parent);
ecs_children_w_rel
ecs_iter_t ecs_children_w_rel(const ecs_world_t *world, ecs_entity_t relationship, ecs_entity_t parent)
Same as ecs_children() but with custom relationship argument.

Parameters

  world | The world.
  parent | The parent.

Returns
  An iterator that iterates all children of the parent.

See also
  ecs_each_id()

## ◆ ecs_children_next()

bool ecs_children_next | ( | ecs_iter_t * | it | ) |

Progress an iterator created with ecs_children().

Parameters

  it | The iterator.

Returns
  True if the iterator has more results, false if not.

## ◆ ecs_children_w_rel()

ecs_iter_t ecs_children_w_rel | ( | const ecs_world_t * | world,
|  | ecs_entity_t | relationship,
|  | ecs_entity_t | parent )

Same as ecs_children() but with custom relationship argument.

Parameters

  world | The world.
  relationship | The relationship.
  parent | The parent.

Returns
  An iterator that iterates all children of the parent.

## ◆ ecs_each_id()

ecs_iter_t ecs_each_id | ( | const ecs_world_t * | world,
|  | ecs_id_t | component )

Iterate all entities with specified (component id).

This returns an iterator that yields all entities with a single specified component. This is a much lighter weight operation than creating and iterating a query.

Usage:

ecs_iter_t it = ecs_each(world, Player);
while (ecs_each_next(&it)) {
for (int i = 0; i < it.count; i ++) {
// Iterate as usual.
}
}
ecs_each_next
bool ecs_each_next(ecs_iter_t *it)
Progress an iterator created with ecs_each_id().
ecs_iter_t::count
int32_t count
Number of entities to iterate.
Definition flecs.h:1149

If the specified id is a component, it is possible to access the component pointer with ecs_field just like with regular queries:

ecs_iter_t it = ecs_each(world, Position);
while (ecs_each_next(&it)) {
Position *p = ecs_field(&it, Position, 0);
for (int i = 0; i < it.count; i ++) {
// Iterate as usual.
}
}

Parameters

  world | The world.
  component | The component to iterate.

Returns
  An iterator that iterates all entities with the (component) id.

## ◆ ecs_each_next()

bool ecs_each_next | ( | ecs_iter_t * | it | ) |

Progress an iterator created with ecs_each_id().

Parameters

  it | The iterator.

Returns
  True if the iterator has more results, false if not.