-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Query::get_multiple for accessing multiple entities simultaneously from the same query #2276
Comments
Unsurprisingly, a parallel API for direct world access is probably a good idea too. |
rust-lang/rfcs#3100 treads similar ground, creating a trait for this style of functionality in the standard library. We could migrate this functionality to use that trait later once it's stabilized. |
Duplicate of #2042. |
Just fyi, if you really really want access to multiple entries, then you might consider a cuckoo table. Those could've some |
Really neat data structure! Would the main benefits be performance? |
I'm unsure how performance works out, usually cuckoo filters wind up more memory efficent. I think few people use them because all the optimizations look more subtle than hash tables. Afaik they work fine with the same good hashers and hash tables, like SipHash or HashBrown, but they're more sensitive to bad hashers, and some devs love plugging in bad hasher for speed. |
What problem does this solve or what need does it fill?
When working with queries, you sometimes need to access the data on multiple components at once. This is particularly frustrating if you require mutable access, due to Rust's borrow checking rules.
What solution would you like?
Add the
Query::get_multiple(entities: HashSet<Entity>) -> HashMap<Entity, Result<[Elided](https://docs.rs/bevy/0.5.0/bevy/ecs/system/struct.Query.html#method.get_mut)>>
method and the associatedget_multiple_mut
. By passing in a HashSet of entities, we can ensure that we never have mutable access to the entities at the same time.Also add
get_component
analogues for this pattern.What alternative(s) have you considered?
iter_combinations
solves the common case, but other more bespoke access patterns certainly exist.You can work around this by storing data, but that only works for
Clone
components.@TheRawMeatball felt this should use a different API / impl:
Additional context
#1470 may be easier to work around with this style of API.
It may make sense to use this implementation for
iter_combinations
in some way, but be mindful of perf as iter_combinations is likely to be used in tight loops for things like collision detection.The text was updated successfully, but these errors were encountered: