Skip to content

Commit e3384bb

Browse files
authored
Fix wrong method call in relationship replacement command (#18824)
Fixes a small mix-up from #18058, which added bulk relationship replacement methods. `EntityCommands::replace_related_with_difference` calls `EntityWorldMut::replace_children_with_difference` instead of `EntityWorldMut::replace_related_with_difference`, which means it always operates on the `ChildOf` relationship instead of the `R: Relationship` generic it's provided. `EntityCommands::replace_children_with_difference` takes an `R: Relationship` generic that it shouldn't, but it accidentally works correctly on `main` because it calls the above method.
1 parent 9254297 commit e3384bb

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

crates/bevy_ecs/src/hierarchy.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
bundle::Bundle,
1313
component::{Component, HookContext},
1414
entity::Entity,
15-
relationship::{RelatedSpawner, RelatedSpawnerCommands, Relationship},
15+
relationship::{RelatedSpawner, RelatedSpawnerCommands},
1616
system::EntityCommands,
1717
world::{DeferredWorld, EntityWorldMut, FromWorld, World},
1818
};
@@ -88,6 +88,8 @@ use log::warn;
8888
/// assert_eq!(&**world.entity(root).get::<Children>().unwrap(), &[child1, child2]);
8989
/// assert_eq!(&**world.entity(child1).get::<Children>().unwrap(), &[grandchild]);
9090
/// ```
91+
///
92+
/// [`Relationship`]: crate::relationship::Relationship
9193
#[derive(Component, Clone, PartialEq, Eq, Debug)]
9294
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
9395
#[cfg_attr(
@@ -141,6 +143,7 @@ impl FromWorld for ChildOf {
141143
/// using the [`IntoIterator`] trait.
142144
/// For more complex access patterns, see the [`RelationshipTarget`] trait.
143145
///
146+
/// [`Relationship`]: crate::relationship::Relationship
144147
/// [`RelationshipTarget`]: crate::relationship::RelationshipTarget
145148
#[derive(Component, Default, Debug, PartialEq, Eq)]
146149
#[relationship_target(relationship = ChildOf, linked_spawn)]
@@ -387,13 +390,13 @@ impl<'a> EntityCommands<'a> {
387390
/// # Panics
388391
///
389392
/// Panics when debug assertions are enabled if an invariant is is broken and the command is executed.
390-
pub fn replace_children_with_difference<R: Relationship>(
393+
pub fn replace_children_with_difference(
391394
&mut self,
392395
entities_to_unrelate: &[Entity],
393396
entities_to_relate: &[Entity],
394397
newly_related_entities: &[Entity],
395398
) -> &mut Self {
396-
self.replace_related_with_difference::<R>(
399+
self.replace_related_with_difference::<ChildOf>(
397400
entities_to_unrelate,
398401
entities_to_relate,
399402
newly_related_entities,

crates/bevy_ecs/src/relationship/related_methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ impl<'a> EntityCommands<'a> {
413413
let newly_related_entities: Box<[Entity]> = newly_related_entities.into();
414414

415415
self.queue(move |mut entity: EntityWorldMut| {
416-
entity.replace_children_with_difference(
416+
entity.replace_related_with_difference::<R>(
417417
&entities_to_unrelate,
418418
&entities_to_relate,
419419
&newly_related_entities,

0 commit comments

Comments
 (0)