From c8d30edf1a031e9ce3b79b45597a916f35cf4b43 Mon Sep 17 00:00:00 2001 From: databasedav <31483365+databasedav@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:11:06 -0700 Subject: [PATCH] add `SystemIdMarker` `Component` to enable filtering for `SystemId` `Entity`s (#14584) # Objective Enables writing queries like `Query>` to filter `Entity`s that are, or are not (with `Without`), `SystemId`s. ## Solution Simple unit struct `SystemIdMarker` added during `World::register_boxed_system`; `World::remove_system` already despawns the entity, removing the marker. ## Testing No tests, but happy to write some with direction. Co-authored-by: Alice Cecile --- crates/bevy_ecs/src/system/system_registry.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/bevy_ecs/src/system/system_registry.rs b/crates/bevy_ecs/src/system/system_registry.rs index 10b5790318..f6cf792f71 100644 --- a/crates/bevy_ecs/src/system/system_registry.rs +++ b/crates/bevy_ecs/src/system/system_registry.rs @@ -12,6 +12,10 @@ struct RegisteredSystem { system: BoxedSystem, } +/// Marker [`Component`](bevy_ecs::component::Component) for identifying [`SystemId`] [`Entity`]s. +#[derive(Component)] +pub struct SystemIdMarker; + /// A system that has been removed from the registry. /// It contains the system and whether or not it has been initialized. /// @@ -125,10 +129,13 @@ impl World { ) -> SystemId { SystemId { entity: self - .spawn(RegisteredSystem { - initialized: false, - system, - }) + .spawn(( + RegisteredSystem { + initialized: false, + system, + }, + SystemIdMarker, + )) .id(), marker: std::marker::PhantomData, }