Skip to content

Add .empty() convenience function to Query #2270

@Sheepyhead

Description

@Sheepyhead

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

I find myself occasionally want to check on game state in the way that I want to know if any entities of a given query exist already, but I don't need to use the actual query data. For instance whether the I button opens or closes the inventory window in my game depends on whether the inventory window is already open, and this is most directly checked by finding the marker component for the inventory window.

What solution would you like?

The quick solution would be simply a .empty() function on Query that returns true if the query matches no entities and false otherwise. More ideally I'd also like to be able to make a Query<(), (With<A>, Without<B>, Changed<C>)> so that no data is even passed to the function other than whether the query matches anything or not (having number of matches may be useful but I have no use cases for that currently)

What alternative(s) have you considered?

Currently I write my query like Query<Entity, (With<A>, Without<B>, Changed<C>)> and check on matches using query.iter().count() == 0 which is both wordy and not immediatly explicit. query.empty() would be much nicer

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleD-TrivialNice and easy! A great choice to get started with Bevy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions