From d80e61b8a49f23ae94f750f5eca6bc99058d1882 Mon Sep 17 00:00:00 2001 From: Tim Blackbird Date: Tue, 15 Jul 2025 20:18:58 +0200 Subject: [PATCH] Adjust docs and target getters of `On` and `ObserverTrigger` --- crates/bevy_ecs/src/observer/system_param.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/crates/bevy_ecs/src/observer/system_param.rs b/crates/bevy_ecs/src/observer/system_param.rs index 0b711c4309..71687a55ac 100644 --- a/crates/bevy_ecs/src/observer/system_param.rs +++ b/crates/bevy_ecs/src/observer/system_param.rs @@ -106,23 +106,19 @@ impl<'w, E, B: Bundle> On<'w, E, B> { } impl<'w, E: EntityEvent, B: Bundle> On<'w, E, B> { - /// Returns the [`Entity`] that was targeted by the `event` that triggered this observer. + /// Returns the [`Entity`] that was targeted by the [`EntityEvent`] that triggered this observer. /// /// Note that if event propagation is enabled, this may not be the same as the original target of the event, /// which can be accessed via [`On::original_target`]. - /// - /// If the event was not targeted at a specific entity, this will return [`Entity::PLACEHOLDER`]. pub fn target(&self) -> Entity { - self.trigger.current_target.unwrap_or(Entity::PLACEHOLDER) + self.trigger.current_target.unwrap() } - /// Returns the original [`Entity`] that the `event` was targeted at when it was first triggered. + /// Returns the original [`Entity`] that the [`EntityEvent`] was targeted at when it was first triggered. /// /// If event propagation is not enabled, this will always return the same value as [`On::target`]. - /// - /// If the event was not targeted at a specific entity, this will return [`Entity::PLACEHOLDER`]. pub fn original_target(&self) -> Entity { - self.trigger.original_target.unwrap_or(Entity::PLACEHOLDER) + self.trigger.original_target.unwrap() } /// Enables or disables event propagation, allowing the same event to trigger observers on a chain of different entities. @@ -185,11 +181,11 @@ pub struct ObserverTrigger { pub event_key: EventKey, /// The [`ComponentId`]s the trigger targeted. pub components: SmallVec<[ComponentId; 2]>, - /// The entity that the entity-event targeted, if any. + /// For [`EntityEvent`]s this is the entity that the event targeted. Always `None` for [`BroadcastEvent`]. /// /// Note that if event propagation is enabled, this may not be the same as [`ObserverTrigger::original_target`]. pub current_target: Option, - /// The entity that the entity-event was originally targeted at, if any. + /// For [`EntityEvent`]s this is the entity that the event was originally targeted at. Always `None` for [`BroadcastEvent`]. /// /// If event propagation is enabled, this will be the first entity that the event was targeted at, /// even if the event was propagated to other entities.