Skip to content

Parent -> ChildOf #17427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions benches/benches/bevy_ecs/entity_cloning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::hint::black_box;
use benches::bench;
use bevy_ecs::bundle::Bundle;
use bevy_ecs::component::ComponentCloneHandler;
use bevy_ecs::hierarchy::Parent;
use bevy_ecs::hierarchy::ChildOf;
use bevy_ecs::reflect::AppTypeRegistry;
use bevy_ecs::{component::Component, world::World};
use bevy_math::Mat4;
Expand Down Expand Up @@ -142,7 +142,7 @@ fn bench_clone_hierarchy<B: Bundle + Default + GetTypeRegistration>(

for parent_id in current_hierarchy_level {
for _ in 0..children {
let child_id = world.spawn((B::default(), Parent(parent_id))).id();
let child_id = world.spawn((B::default(), ChildOf(parent_id))).id();
hierarchy_level.push(child_id);
}
}
Expand Down
2 changes: 1 addition & 1 deletion benches/benches/bevy_ecs/observers/propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn event_propagation(criterion: &mut Criterion) {
struct TestEvent<const N: usize> {}

impl<const N: usize> Event for TestEvent<N> {
type Traversal = &'static Parent;
type Traversal = &'static ChildOf;
const AUTO_PROPAGATE: bool = true;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Default for App {
{
app.init_resource::<AppTypeRegistry>();
app.register_type::<Name>();
app.register_type::<Parent>();
app.register_type::<ChildOf>();
app.register_type::<Children>();
}

Expand Down
19 changes: 11 additions & 8 deletions crates/bevy_ecs/src/entity/clone_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
bundle::Bundle,
component::{Component, ComponentCloneHandler, ComponentId, ComponentInfo, Components},
entity::Entity,
hierarchy::{Children, Parent},
hierarchy::{ChildOf, Children},
query::DebugCheckedUnwrap,
world::{DeferredWorld, World},
};
Expand Down Expand Up @@ -637,11 +637,11 @@ impl<'w> EntityCloneBuilder<'w> {
/// Sets the option to add cloned entity as a child to the parent entity.
pub fn as_child(&mut self, as_child: bool) -> &mut Self {
if as_child {
self.override_component_clone_handler::<Parent>(ComponentCloneHandler::custom_handler(
self.override_component_clone_handler::<ChildOf>(ComponentCloneHandler::custom_handler(
component_clone_parent,
))
} else {
self.remove_component_clone_handler_override::<Parent>()
self.remove_component_clone_handler_override::<ChildOf>()
}
}

Expand Down Expand Up @@ -700,18 +700,21 @@ fn component_clone_children(world: &mut DeferredWorld, ctx: &mut ComponentCloneC
.with_source_and_target(*child, child_clone);
world.commands().queue(move |world: &mut World| {
clone_entity.clone_entity(world);
world.entity_mut(child_clone).insert(Parent(parent));
world.entity_mut(child_clone).insert(ChildOf(parent));
});
}
}

/// Clone handler for the [`Parent`] component. Allows to add clone as a child to the parent entity.
/// Clone handler for the [`ChildOf`] component. Allows to add clone as a child to the parent entity.
fn component_clone_parent(world: &mut DeferredWorld, ctx: &mut ComponentCloneCtx) {
let parent = ctx
.read_source_component::<Parent>()
.read_source_component::<ChildOf>()
.map(|p| p.0)
.expect("Source entity must have Parent component");
world.commands().entity(ctx.target()).insert(Parent(parent));
.expect("Source entity must have a ChildOf component");
world
.commands()
.entity(ctx.target())
.insert(ChildOf(parent));
}

#[cfg(test)]
Expand Down
Loading
Loading