Skip to content

Add in_any_state and in_all_states run conditions #11221

@ramirezmike

Description

@ramirezmike

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

As games get more complex, users may find themselves wanting to setup a chain of systems to run in multiple separate states or on specific variant overlaps of multiple state types. While this is currently possible with combinator operations, it can be verbose and these patterns may be common enough to have dedicated run conditions. Searching for "or_else" on the discord yields quite a few instances of people asking (👀) how to do an OR with states.

What solution would you like?

Add two run conditions for handling multiple states: in_any_state for OR and in_all_states for AND. There's a good example to start from here for the OR version.

What alternative(s) have you considered?

Using or_else or and_then will suffice but again, it can get verbose

.run_if(in_state(AppState::InGame).or_else(in_state(OtherState::PreGame)).or_else(in_state(AppState::TitleScreen)))

versus

.run_if(in_any_state([AppState::InGame, OtherState::PreGame, AppState::TitleScreen]))

Additional context

The "in_any_state" may be a bit more useful than the "in_all_states" as the latter is only useful if you're using multiple types of States. Additionally, depending on changes like #9942 this might get more complicated or be handled differently anyway?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useX-Needs-SMEThis type of work requires an SME to approve it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions