SanderMertens / flecs

A fast entity component system (ECS) for C & C++
https://www.flecs.dev
Other
6.47k stars 454 forks source link

Iterating over entities with disabled components #364

Closed jtferson closed 4 months ago

jtferson commented 3 years ago

Describe the problem you are trying to solve. Currently entities with disabled components are prevented from being matched. It might be useful in some scenarios to iterate over entities with such components.

Describe the solution you'd like The query signature can accept DISABLED modifier (or something like this) and allow to match with entities that have disabled components:

auto entity = ecs.entity()
    .add<Movable>()
    .add<Velocity>();
entity.disable<Velocity>();

ecs.system<>().signature("DISABLED | Velocity, Movable").iter([](flecs::iter& it)
{
    for(auto i : it)
    {
        //here could be some conditional logic, for example
        if(canEnable)
        {
            it.entity(i).enable<Velocity>();
        }
    } 
});
SanderMertens commented 4 months ago

This is possible in v4:

    ecs.query_builder()
        .expr("toggle | Velocity")
        .each([](flecs::entity e) {
          // ..
        });