Clarify a comment in Option WorldQuery impl (#9749)
I found a comment a bit confusing ## Solution Reword it. --------- Co-authored-by: Joseph <21144246+JoJoJet@users.noreply.github.com>
This commit is contained in:
parent
19c53578e6
commit
d3beaff56f
@ -1218,10 +1218,15 @@ unsafe impl<T: WorldQuery> WorldQuery for Option<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_component_access(state: &T::State, access: &mut FilteredAccess<ComponentId>) {
|
fn update_component_access(state: &T::State, access: &mut FilteredAccess<ComponentId>) {
|
||||||
// We don't want to add the `with`/`without` of `T` as `Option<T>` will match things regardless of
|
// FilteredAccess::add_[write,read] adds the component to the `with` filter.
|
||||||
// `T`'s filters. for example `Query<(Option<&U>, &mut V)>` will match every entity with a `V` component
|
// Those methods are called on `access` in `T::update_component_access`.
|
||||||
// regardless of whether it has a `U` component. If we don't do this the query will not conflict with
|
// But in `Option<T>`, we specifically don't filter on `T`,
|
||||||
// `Query<&mut V, Without<U>>` which would be unsound.
|
// since `(Option<T>, &OtherComponent)` should be a valid item, even
|
||||||
|
// if `Option<T>` is `None`.
|
||||||
|
//
|
||||||
|
// We pass a clone of the `FilteredAccess` to `T`, and only update the `Access`
|
||||||
|
// using `extend_access` so that we can apply `T`'s component_access
|
||||||
|
// without updating the `with` filters of `access`.
|
||||||
let mut intermediate = access.clone();
|
let mut intermediate = access.clone();
|
||||||
T::update_component_access(state, &mut intermediate);
|
T::update_component_access(state, &mut intermediate);
|
||||||
access.extend_access(&intermediate);
|
access.extend_access(&intermediate);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user