Skip to content

Add Has<C> WorldQuery type to replace Option<&C> when checking existence #7811

Closed
@alice-i-cecile

Description

@alice-i-cecile

What problem does this solve or what need does it fill?

I commonly find myself reaching for Option<&C> when I just need to check whether or not a component exists, and then branching on Some versus None.

This works well enough, but:

  1. The access is more restrictive than it needs to be: we request read access, but only actually need existence checking. This limits parallelism, as these systems could run in parallel with mutating systems.
  2. It's less clear to read: the pattern is a bit strange and implicit.
  3. It may be measurably slower.

What solution would you like?

Add a Has<C: Component> type. Implement WorldQuery for this, with no access required.

The item type of each query element should be bool.

What alternative(s) have you considered?

We could do nothing, the eixisting pattern isn't terrible.

We could name this Is<C>: I'm not sure which one is clearer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possible

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions