Skip to content

Commit a9b0fe7

Browse files
committed
Add set_relation_filter method to Query
1 parent 13b82b4 commit a9b0fe7

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

crates/bevy_ecs/src/query/state.rs

-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ where
3535
pub(crate) archetype_component_access: Access<ArchetypeComponentId>,
3636
pub(crate) component_access: FilteredAccess<RelationKindId>,
3737

38-
// FIXME(Relationships) We need to clear this on `Query` drop impl so that filters dont
39-
// persist across system executions
4038
pub(crate) current_relation_filter: QueryRelationFilter<Q, F>,
4139
pub(crate) relation_filter_accesses: HashMap<QueryRelationFilter<Q, F>, QueryAccessCache>,
4240

crates/bevy_ecs/src/system/query.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{
22
component::Component,
33
entity::Entity,
4+
prelude::QueryRelationFilter,
45
query::{
56
Fetch, FilterFetch, QueryEntityError, QueryIter, QueryState, ReadOnlyFetch, WorldQuery,
67
},
@@ -214,6 +215,8 @@ where
214215
.get_unchecked_manual(self.world, entity, self.last_change_tick, self.change_tick)
215216
}
216217

218+
// FIXME(Relationships) we likely want get_relation methods for both `T *` and `T some_entity`
219+
217220
/// Gets a reference to the entity's component of the given type. This will fail if the entity
218221
/// does not have the given component type or if the given component type does not match
219222
/// this query.
@@ -352,6 +355,19 @@ where
352355
>())),
353356
}
354357
}
358+
359+
pub fn set_relation_filter(&mut self, relation_filter: QueryRelationFilter<Q, F>) {
360+
self.state.set_relation_filter(&self.world, relation_filter);
361+
}
362+
}
363+
364+
impl<'w, Q: WorldQuery, F: WorldQuery> Drop for Query<'w, Q, F>
365+
where
366+
F::Fetch: FilterFetch,
367+
{
368+
fn drop(&mut self) {
369+
self.set_relation_filter(QueryRelationFilter::new());
370+
}
355371
}
356372

357373
/// An error that occurs when retrieving a specific [Entity]'s component from a [Query]

crates/bevy_scene/src/dynamic_scene.rs

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ impl DynamicScene {
3838

3939
for (kind_id, _) in archetype.components() {
4040
let kind_info = world.components().get_relation_kind(kind_id);
41-
// FIXME(Relationships) getting the TypeId here looks suspicious :thinking:
4241
let reflect_component = type_registry
4342
.get(kind_info.data_layout().type_id().unwrap())
4443
.and_then(|registration| registration.data::<ReflectComponent>());

0 commit comments

Comments
 (0)