From 0fc60b68a4ca1713015b0b697c59eb932bec50a7 Mon Sep 17 00:00:00 2001 From: Lukas Orsvarn Date: Sun, 29 Nov 2020 15:24:56 +0100 Subject: [PATCH 1/2] Add documentation for bevy::ecs::Query::removed --- crates/bevy_ecs/src/system/query/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/bevy_ecs/src/system/query/mod.rs b/crates/bevy_ecs/src/system/query/mod.rs index 5fa89aa9d0f1d..2d9e4e9f125d9 100644 --- a/crates/bevy_ecs/src/system/query/mod.rs +++ b/crates/bevy_ecs/src/system/query/mod.rs @@ -181,6 +181,12 @@ impl<'a, Q: WorldQuery, F: QueryFilter> Query<'a, Q, F> { .map_err(QueryError::ComponentError) } + /// Returns an array containing the entities in this query that had the given component + /// removed in this update. + /// + /// This function needs to be executed on some stage *after* the removal of the component, + /// otherwise the component hasn't actually been removed yet. + /// `AppBuilder::add_system_to_stage` can be used to control at what stage a system runs. pub fn removed(&self) -> &[Entity] { self.world.removed::() } From 013d15f41b3dc18cd0cecc9c4640a8eb280fd53f Mon Sep 17 00:00:00 2001 From: Lukas Orsvarn Date: Sat, 5 Dec 2020 11:27:23 +0100 Subject: [PATCH 2/2] Changes based on feedback --- crates/bevy_ecs/src/system/query/mod.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/bevy_ecs/src/system/query/mod.rs b/crates/bevy_ecs/src/system/query/mod.rs index 2d9e4e9f125d9..60a309a029b76 100644 --- a/crates/bevy_ecs/src/system/query/mod.rs +++ b/crates/bevy_ecs/src/system/query/mod.rs @@ -181,12 +181,21 @@ impl<'a, Q: WorldQuery, F: QueryFilter> Query<'a, Q, F> { .map_err(QueryError::ComponentError) } - /// Returns an array containing the entities in this query that had the given component + /// Returns an array containing the `Entity`s in this `Query` that had the given `Component` /// removed in this update. /// - /// This function needs to be executed on some stage *after* the removal of the component, - /// otherwise the component hasn't actually been removed yet. - /// `AppBuilder::add_system_to_stage` can be used to control at what stage a system runs. + /// `removed::()` only returns entities whose components were removed before the + /// current system started. + /// + /// Regular systems do not apply `Commands` until the end of their stage. This means component + /// removals in a regular system won't be accessible through `removed::()` in the same + /// stage, because the removal hasn't actually occurred yet. This can be solved by executing + /// `removed::()` in a later stage. `AppBuilder::add_system_to_stage()` can be used to + /// control at what stage a system runs. + /// + /// Thread local systems manipulate the world directly, so removes are applied immediately. This + /// means any system that runs after a thread local system in the same update will pick up + /// removals that happened in the thread local system, regardless of stages. pub fn removed(&self) -> &[Entity] { self.world.removed::() }