Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion crates/bevy_ecs/src/relationship/related_methods.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::{
bundle::Bundle,
entity::{hash_set::EntityHashSet, Entity},
event::Event,
observer::Observer,
relationship::{
Relationship, RelationshipHookMode, RelationshipSourceCollection, RelationshipTarget,
},
system::{Commands, EntityCommands},
system::{Commands, EntityCommands, IntoObserverSystem},
world::{EntityWorldMut, World},
};
use bevy_platform::prelude::{Box, Vec};
Expand Down Expand Up @@ -527,6 +529,17 @@ impl<'w, R: Relationship> RelatedSpawner<'w, R> {
self.world.spawn(R::from(self.target))
}

/// Creates an [`Observer`] listening for events of type 'E' targeting the 'target'
/// entity this spawner was initialized with. No relationship 'R' is created
/// between the [`Observer`] and the 'target' entity.
pub fn observe_target<E: Event, B: Bundle, M>(
&mut self,
observer: impl IntoObserverSystem<E, B, M>,
) -> EntityWorldMut<'_> {
self.world
.spawn(Observer::new(observer).with_entity(self.target))
}

/// Returns the "target entity" used when spawning entities with an `R` [`Relationship`].
pub fn target_entity(&self) -> Entity {
self.target
Expand Down