Skip to content

Commit a0f9e5c

Browse files
cartmrchantey
authored andcommitted
Parent -> ChildOf (bevyengine#17427)
Fixes bevyengine#17412 ## Objective `Parent` uses the "has a X" naming convention. There is increasing sentiment that we should use the "is a X" naming convention for relationships (following bevyengine#17398). This leaves `Children` as-is because there is prevailing sentiment that `Children` is clearer than `ParentOf` in many cases (especially when treating it like a collection). This renames `Parent` to `ChildOf`. This is just the implementation PR. To discuss the path forward, do so in bevyengine#17412. ## Migration Guide - The `Parent` component has been renamed to `ChildOf`.
1 parent a7a6c38 commit a0f9e5c

File tree

34 files changed

+203
-197
lines changed

34 files changed

+203
-197
lines changed

benches/benches/bevy_ecs/entity_cloning.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::hint::black_box;
33
use benches::bench;
44
use bevy_ecs::bundle::Bundle;
55
use bevy_ecs::component::ComponentCloneHandler;
6-
use bevy_ecs::hierarchy::Parent;
6+
use bevy_ecs::hierarchy::ChildOf;
77
use bevy_ecs::reflect::AppTypeRegistry;
88
use bevy_ecs::{component::Component, world::World};
99
use bevy_math::Mat4;
@@ -142,7 +142,7 @@ fn bench_clone_hierarchy<B: Bundle + Default + GetTypeRegistration>(
142142

143143
for parent_id in current_hierarchy_level {
144144
for _ in 0..children {
145-
let child_id = world.spawn((B::default(), Parent(parent_id))).id();
145+
let child_id = world.spawn((B::default(), ChildOf(parent_id))).id();
146146
hierarchy_level.push(child_id);
147147
}
148148
}

benches/benches/bevy_ecs/observers/propagation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn event_propagation(criterion: &mut Criterion) {
6565
struct TestEvent<const N: usize> {}
6666

6767
impl<const N: usize> Event for TestEvent<N> {
68-
type Traversal = &'static Parent;
68+
type Traversal = &'static ChildOf;
6969
const AUTO_PROPAGATE: bool = true;
7070
}
7171

crates/bevy_app/src/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl Default for App {
107107
{
108108
app.init_resource::<AppTypeRegistry>();
109109
app.register_type::<Name>();
110-
app.register_type::<Parent>();
110+
app.register_type::<ChildOf>();
111111
app.register_type::<Children>();
112112
}
113113

crates/bevy_ecs/src/entity/clone_entities.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
bundle::Bundle,
1313
component::{Component, ComponentCloneHandler, ComponentId, ComponentInfo, Components},
1414
entity::Entity,
15-
hierarchy::{Children, Parent},
15+
hierarchy::{ChildOf, Children},
1616
query::DebugCheckedUnwrap,
1717
world::{DeferredWorld, World},
1818
};
@@ -631,11 +631,11 @@ impl<'w> EntityCloneBuilder<'w> {
631631
/// Sets the option to add cloned entity as a child to the parent entity.
632632
pub fn as_child(&mut self, as_child: bool) -> &mut Self {
633633
if as_child {
634-
self.override_component_clone_handler::<Parent>(ComponentCloneHandler::custom_handler(
634+
self.override_component_clone_handler::<ChildOf>(ComponentCloneHandler::custom_handler(
635635
component_clone_parent,
636636
))
637637
} else {
638-
self.remove_component_clone_handler_override::<Parent>()
638+
self.remove_component_clone_handler_override::<ChildOf>()
639639
}
640640
}
641641

@@ -694,18 +694,21 @@ fn component_clone_children(world: &mut DeferredWorld, ctx: &mut ComponentCloneC
694694
.with_source_and_target(*child, child_clone);
695695
world.commands().queue(move |world: &mut World| {
696696
clone_entity.clone_entity(world);
697-
world.entity_mut(child_clone).insert(Parent(parent));
697+
world.entity_mut(child_clone).insert(ChildOf(parent));
698698
});
699699
}
700700
}
701701

702-
/// Clone handler for the [`Parent`] component. Allows to add clone as a child to the parent entity.
702+
/// Clone handler for the [`ChildOf`] component. Allows to add clone as a child to the parent entity.
703703
fn component_clone_parent(world: &mut DeferredWorld, ctx: &mut ComponentCloneCtx) {
704704
let parent = ctx
705-
.read_source_component::<Parent>()
705+
.read_source_component::<ChildOf>()
706706
.map(|p| p.0)
707-
.expect("Source entity must have Parent component");
708-
world.commands().entity(ctx.target()).insert(Parent(parent));
707+
.expect("Source entity must have a ChildOf component");
708+
world
709+
.commands()
710+
.entity(ctx.target())
711+
.insert(ChildOf(parent));
709712
}
710713

711714
#[cfg(test)]

0 commit comments

Comments
 (0)