OneOf WorldQuery via a Xor filter, alternative to Enum filtering #9649
Labels
A-ECS
Entities, components, systems, and events
C-Feature
A new feature, making something new possible
D-Modest
A "normal" level of difficulty; suitable for simple features or challenging fixes
S-Ready-For-Implementation
This issue is ready for an implementation PR. Go for it!
What problem does this solve or what need does it fill?
A somewhat common question in the Bevy Discord involves being able to filter by a component's enum variant:
This doesn't work because Rust doesn't represent enum variants as full types. A common alternative is to use marker components instead, but currently you lose out on the mutual exclusivity that standard enums provide.
I propose to add a new
OneOf<(A, B, C, ...)>
WorldQuery similar toAnyOf
, but backed by aXor
filter rather thanOr
.What solution would you like?
Similar to how
AnyOf
works:This new
OneOf
should work like:Could also look at having an enum return type per arity, like
This might be best paired with Archetype Invariants.
What alternative(s) have you considered?
Use enums and deal with its inherent issues manually.
The text was updated successfully, but these errors were encountered: