Skip to content

Commit 0d6579a

Browse files
committed
Remove copying/constructing traits from Parent/Children
1 parent 11e2e23 commit 0d6579a

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

crates/bevy_transform/src/components/children.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
use bevy_ecs::{
22
component::Component,
33
entity::{Entity, EntityMap, MapEntities, MapEntitiesError},
4+
prelude::FromWorld,
45
reflect::{ReflectComponent, ReflectMapEntities},
6+
world::World,
57
};
68
use bevy_reflect::Reflect;
79
use smallvec::SmallVec;
810
use std::ops::Deref;
911

1012
/// Contains references to the child entities of this entity
11-
#[derive(Component, Default, Clone, Debug, Reflect)]
13+
#[derive(Component, Debug, Reflect)]
1214
#[reflect(Component, MapEntities)]
1315
pub struct Children(pub(crate) SmallVec<[Entity; 8]>);
1416

@@ -22,6 +24,16 @@ impl MapEntities for Children {
2224
}
2325
}
2426

27+
// TODO: We need to impl either FromWorld or Default so Children can be registered as Reflect.
28+
// This is because Reflect deserialize by creating an instance and apply a patch on top.
29+
// However Children should only ever be set with a real user-defined entities. Its worth looking
30+
// into better ways to handle cases like this.
31+
impl FromWorld for Children {
32+
fn from_world(_world: &mut World) -> Self {
33+
Children(SmallVec::new())
34+
}
35+
}
36+
2537
impl Children {
2638
/// Builds and returns a [`Children`] component with the given entities
2739
pub fn with(entity: &[Entity]) -> Self {

crates/bevy_transform/src/components/parent.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ use std::ops::Deref;
99

1010
/// Holds a reference to the parent entity of this entity.
1111
/// This component should only be present on entities that actually have a parent entity.
12-
#[derive(Component, Debug, Copy, Clone, Eq, PartialEq, Reflect)]
12+
#[derive(Component, Debug, Eq, PartialEq, Reflect)]
1313
#[reflect(Component, MapEntities, PartialEq)]
1414
pub struct Parent(pub(crate) Entity);
1515

16-
// TODO: We need to impl either FromWorld or Default so Parent can be registered as Properties.
17-
// This is because Properties deserialize by creating an instance and apply a patch on top.
16+
// TODO: We need to impl either FromWorld or Default so Parent can be registered as Reflect.
17+
// This is because Reflect deserialize by creating an instance and apply a patch on top.
1818
// However Parent should only ever be set with a real user-defined entity. Its worth looking into
1919
// better ways to handle cases like this.
2020
impl FromWorld for Parent {

crates/bevy_transform/src/hierarchy/child_builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ fn push_child_unchecked(world: &mut World, parent: Entity, child: Entity) {
5050
fn update_parent(world: &mut World, child: Entity, new_parent: Entity) -> Option<Entity> {
5151
let mut child = world.entity_mut(child);
5252
if let Some(mut parent) = child.get_mut::<Parent>() {
53-
let previous = *parent;
53+
let previous = parent.0;
5454
*parent = Parent(new_parent);
55-
Some(*previous)
55+
Some(previous)
5656
} else {
5757
child.insert(Parent(new_parent));
5858
None

0 commit comments

Comments
 (0)