From f39320d0c772356f57079d321546eac80ffb31ee Mon Sep 17 00:00:00 2001 From: urben1680 <55257931+urben1680@users.noreply.github.com> Date: Tue, 6 May 2025 07:18:56 +0200 Subject: [PATCH] Add `world` and `world_mut` methods to `RelatedSpawner` (#18880) # Objective `RelatedSpawnerCommands` offers methods to get the underlying `Commands`. `RelatedSpawner` does not expose the inner `World` reference so far. I currently want to write extension traits for both of them but I need to duplicate the whole API for the latter because I cannot get it's `&mut World`. ## Solution Add methods for immutable and mutable `World` access --- crates/bevy_ecs/src/relationship/related_methods.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/bevy_ecs/src/relationship/related_methods.rs b/crates/bevy_ecs/src/relationship/related_methods.rs index 98ef8d0832..b53fd43943 100644 --- a/crates/bevy_ecs/src/relationship/related_methods.rs +++ b/crates/bevy_ecs/src/relationship/related_methods.rs @@ -519,6 +519,16 @@ impl<'w, R: Relationship> RelatedSpawner<'w, R> { pub fn target_entity(&self) -> Entity { self.target } + + /// Returns a reference to the underlying [`World`]. + pub fn world(&self) -> &World { + self.world + } + + /// Returns a mutable reference to the underlying [`World`]. + pub fn world_mut(&mut self) -> &mut World { + self.world + } } /// Uses commands to spawn related "source" entities with the given [`Relationship`], targeting