-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add Has<C>
WorldQuery
type to replace Option<&C>
when checking existence
#7811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It's pretty horrible but |
Ah right, that's caused by #7680. |
|
sidenote: |
james7132
pushed a commit
to james7132/bevy
that referenced
this issue
Jun 19, 2023
# Objective - Fixes bevyengine#7811 ## Solution - I added `Has<T>` (and `HasFetch<T>` ) and implemented `WorldQuery`, `ReadonlyWorldQuery`, and `ArchetypeFilter` it - I also added documentation with an example and a unit test I believe I've done everything right but this is my first contribution and I'm not an ECS expert so someone who is should probably check my implementation. I based it on what `Or<With<T>,>`, would do. The only difference is that `Has` does not update component access - adding `Has` to a query should never affect whether or not it is disjoint with another query *I think*. --- ## Changelog ## Added - Added `Has<T>` WorldQuery to find out whether or not an entity has a particular component. --------- Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: JoJoJet <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 onSome
versusNone
.This works well enough, but:
What solution would you like?
Add a
Has<C: Component>
type. ImplementWorldQuery
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.The text was updated successfully, but these errors were encountered: