Adjust docs and target getters of On and ObserverTrigger

This commit is contained in:
Tim Blackbird 2025-07-15 20:18:58 +02:00
parent bd812cd9e0
commit d80e61b8a4

View File

@ -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<Entity>,
/// 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.