From 75e8e8c0f620f0f156b63f063979bda4b0a91b14 Mon Sep 17 00:00:00 2001 From: Periwink Date: Sun, 2 Feb 2025 15:10:37 -0500 Subject: [PATCH] Expose ObserverDescriptor fields (#17623) # Objective Expose accessor functions to the `ObserverDescriptor`, so that users can use the `Observer` component to inspect what the observer is watching. This would be useful for me, I don't think there's any reason to hide these. --- crates/bevy_ecs/src/observer/mod.rs | 15 +++++++++++++++ crates/bevy_ecs/src/observer/runner.rs | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/crates/bevy_ecs/src/observer/mod.rs b/crates/bevy_ecs/src/observer/mod.rs index b5d55d8798..1fd58610fb 100644 --- a/crates/bevy_ecs/src/observer/mod.rs +++ b/crates/bevy_ecs/src/observer/mod.rs @@ -307,6 +307,21 @@ impl ObserverDescriptor { .extend(descriptor.components.iter().copied()); self.entities.extend(descriptor.entities.iter().copied()); } + + /// Returns the `events` that the observer is watching. + pub fn events(&self) -> &[ComponentId] { + &self.events + } + + /// Returns the `components` that the observer is watching. + pub fn components(&self) -> &[ComponentId] { + &self.components + } + + /// Returns the `entities` that the observer is watching. + pub fn entities(&self) -> &[Entity] { + &self.entities + } } /// Event trigger metadata for a given [`Observer`], diff --git a/crates/bevy_ecs/src/observer/runner.rs b/crates/bevy_ecs/src/observer/runner.rs index 6990d5023b..11ff5eabbc 100644 --- a/crates/bevy_ecs/src/observer/runner.rs +++ b/crates/bevy_ecs/src/observer/runner.rs @@ -312,6 +312,11 @@ impl Observer { self.descriptor.events.push(event); self } + + /// Returns the [`ObserverDescriptor`] for this [`Observer`]. + pub fn descriptor(&self) -> &ObserverDescriptor { + &self.descriptor + } } impl Component for Observer {