Skip to content

Commit 58bb7fd

Browse files
committed
Children -> ParentOf
1 parent 1417e77 commit 58bb7fd

37 files changed

+152
-152
lines changed

Diff for: crates/bevy_app/src/app.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl Default for App {
105105
app.init_resource::<AppTypeRegistry>();
106106
app.register_type::<Name>();
107107
app.register_type::<ChildOf>();
108-
app.register_type::<Children>();
108+
app.register_type::<ParentOf>();
109109
}
110110

111111
#[cfg(feature = "reflect_functions")]

Diff for: crates/bevy_ecs/macros/src/component.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ fn derive_relationship_target(
554554
return Ok(None);
555555
};
556556

557-
const RELATIONSHIP_TARGET_FORMAT_MESSAGE: &str = "RelationshipTarget derives must be a tuple struct with the first element being a private RelationshipSourceCollection (ex: Children(Vec<Entity>))";
557+
const RELATIONSHIP_TARGET_FORMAT_MESSAGE: &str = "RelationshipTarget derives must be a tuple struct with the first element being a private RelationshipSourceCollection (ex: ParentOf(Vec<Entity>))";
558558
let collection = if let Data::Struct(DataStruct {
559559
fields: Fields::Unnamed(unnamed_fields),
560560
struct_token,

Diff for: crates/bevy_ecs/src/entity/clone_entities.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{
1818
bundle::Bundle,
1919
component::{Component, ComponentCloneHandler, ComponentId, ComponentInfo, Components},
2020
entity::Entity,
21-
hierarchy::{ChildOf, Children},
21+
hierarchy::{ChildOf, ParentOf},
2222
query::DebugCheckedUnwrap,
2323
world::{DeferredWorld, World},
2424
};
@@ -626,11 +626,11 @@ impl<'w> EntityCloneBuilder<'w> {
626626
/// When set to true all children will be cloned with the same options as the parent.
627627
pub fn recursive(&mut self, recursive: bool) -> &mut Self {
628628
if recursive {
629-
self.override_component_clone_handler::<Children>(
629+
self.override_component_clone_handler::<ParentOf>(
630630
ComponentCloneHandler::custom_handler(component_clone_children),
631631
)
632632
} else {
633-
self.remove_component_clone_handler_override::<Children>()
633+
self.remove_component_clone_handler_override::<ParentOf>()
634634
}
635635
}
636636

@@ -686,11 +686,11 @@ impl<'w> EntityCloneBuilder<'w> {
686686
}
687687
}
688688

689-
/// Clone handler for the [`Children`] component. Allows to clone the entity recursively.
689+
/// Clone handler for the [`ParentOf`] component. Allows to clone the entity recursively.
690690
fn component_clone_children(world: &mut DeferredWorld, ctx: &mut ComponentCloneCtx) {
691691
let children = ctx
692-
.read_source_component::<Children>()
693-
.expect("Source entity must have Children component")
692+
.read_source_component::<ParentOf>()
693+
.expect("Source entity must have ParentOf component")
694694
.iter();
695695
let parent = ctx.target();
696696
for child in children {

Diff for: crates/bevy_ecs/src/hierarchy.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! The canonical "parent-child" [`Relationship`] for entities, driven by
2-
//! the [`ChildOf`] [`Relationship`] and the [`Children`] [`RelationshipTarget`].
2+
//! the [`ChildOf`] [`Relationship`] and the [`ParentOf`] [`RelationshipTarget`].
33
//!
44
//! See [`ChildOf`] for a full description of the relationship and how to use it.
55
//!
@@ -29,7 +29,7 @@ use log::warn;
2929

3030
/// A [`Relationship`](crate::relationship::Relationship) component that creates the canonical
3131
/// "parent / child" hierarchy. This is the "source of truth" component, and it pairs with
32-
/// the [`Children`] [`RelationshipTarget`](crate::relationship::RelationshipTarget).
32+
/// the [`ParentOf`] [`RelationshipTarget`](crate::relationship::RelationshipTarget).
3333
///
3434
/// This relationship should be used for things like:
3535
///
@@ -39,14 +39,14 @@ use log::warn;
3939
/// 4.
4040
///
4141
/// [`ChildOf`] contains a single "target" [`Entity`]. When [`ChildOf`] is inserted on a "source" entity,
42-
/// the "target" entity will automatically (and immediately, via a component hook) have a [`Children`]
43-
/// component inserted, and the "source" entity will be added to that [`Children`] instance.
42+
/// the "target" entity will automatically (and immediately, via a component hook) have a [`ParentOf`]
43+
/// component inserted, and the "source" entity will be added to that [`ParentOf`] instance.
4444
///
45-
/// If the [`ChildOf`] component is replaced with a different "target" entity, the old target's [`Children`]
45+
/// If the [`ChildOf`] component is replaced with a different "target" entity, the old target's [`ParentOf`]
4646
/// will be automatically (and immediately, via a component hook) be updated to reflect that change.
4747
///
4848
/// Likewise, when the [`ChildOf`] component is removed, the "source" entity will be removed from the old
49-
/// target's [`Children`]. If this results in [`Children`] being empty, [`Children`] will be automatically removed.
49+
/// target's [`ParentOf`]. If this results in [`ParentOf`] being empty, [`ParentOf`] will be automatically removed.
5050
///
5151
/// When a parent is despawned, all children (and their descendants) will _also_ be despawned.
5252
///
@@ -60,11 +60,11 @@ use log::warn;
6060
/// let child2 = world.spawn(ChildOf(root)).id();
6161
/// let grandchild = world.spawn(ChildOf(child1)).id();
6262
///
63-
/// assert_eq!(&**world.entity(root).get::<Children>().unwrap(), &[child1, child2]);
64-
/// assert_eq!(&**world.entity(child1).get::<Children>().unwrap(), &[grandchild]);
63+
/// assert_eq!(&**world.entity(root).get::<ParentOf>().unwrap(), &[child1, child2]);
64+
/// assert_eq!(&**world.entity(child1).get::<ParentOf>().unwrap(), &[grandchild]);
6565
///
6666
/// world.entity_mut(child2).remove::<ChildOf>();
67-
/// assert_eq!(&**world.entity(root).get::<Children>().unwrap(), &[child1]);
67+
/// assert_eq!(&**world.entity(root).get::<ParentOf>().unwrap(), &[child1]);
6868
///
6969
/// world.entity_mut(root).despawn();
7070
/// assert!(world.get_entity(root).is_err());
@@ -87,8 +87,8 @@ use log::warn;
8787
/// child2 = p.spawn_empty().id();
8888
/// }).id();
8989
///
90-
/// assert_eq!(&**world.entity(root).get::<Children>().unwrap(), &[child1, child2]);
91-
/// assert_eq!(&**world.entity(child1).get::<Children>().unwrap(), &[grandchild]);
90+
/// assert_eq!(&**world.entity(root).get::<ParentOf>().unwrap(), &[child1, child2]);
91+
/// assert_eq!(&**world.entity(child1).get::<ParentOf>().unwrap(), &[grandchild]);
9292
/// ```
9393
#[derive(Component, Clone, VisitEntities, VisitEntitiesMut, PartialEq, Eq, Debug)]
9494
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
@@ -104,7 +104,7 @@ use log::warn;
104104
FromWorld
105105
)
106106
)]
107-
#[relationship(relationship_target = Children)]
107+
#[relationship(relationship_target = ParentOf)]
108108
pub struct ChildOf(pub Entity);
109109

110110
impl ChildOf {
@@ -146,9 +146,9 @@ impl FromWorld for ChildOf {
146146
feature = "bevy_reflect",
147147
reflect(Component, MapEntities, VisitEntities, VisitEntitiesMut, FromWorld)
148148
)]
149-
pub struct Children(Vec<Entity>);
149+
pub struct ParentOf(Vec<Entity>);
150150

151-
impl<'a> IntoIterator for &'a Children {
151+
impl<'a> IntoIterator for &'a ParentOf {
152152
type Item = <Self::IntoIter as Iterator>::Item;
153153

154154
type IntoIter = slice::Iter<'a, Entity>;
@@ -159,7 +159,7 @@ impl<'a> IntoIterator for &'a Children {
159159
}
160160
}
161161

162-
impl Deref for Children {
162+
impl Deref for ParentOf {
163163
type Target = [Entity];
164164

165165
fn deref(&self) -> &Self::Target {
@@ -297,7 +297,7 @@ pub fn validate_parent_has_component<C: Component>(
297297
mod tests {
298298
use crate::{
299299
entity::Entity,
300-
hierarchy::{ChildOf, Children},
300+
hierarchy::{ChildOf, ParentOf},
301301
relationship::RelationshipTarget,
302302
world::World,
303303
};
@@ -327,7 +327,7 @@ mod tests {
327327
entity,
328328
children: world
329329
.entity(entity)
330-
.get::<Children>()
330+
.get::<ParentOf>()
331331
.map_or_else(Default::default, |c| {
332332
c.iter().map(|e| get_hierarchy(world, e)).collect()
333333
}),

Diff for: crates/bevy_ecs/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub mod prelude {
7575
component::{require, Component},
7676
entity::{Entity, EntityBorrow, EntityMapper},
7777
event::{Event, EventMutator, EventReader, EventWriter, Events},
78-
hierarchy::{ChildSpawner, ChildSpawnerCommands, Children, ChildOf},
78+
hierarchy::{ChildOf, ChildSpawner, ChildSpawnerCommands, ParentOf},
7979
name::{Name, NameOrEntity},
8080
observer::{CloneEntityWithObserversExt, Observer, Trigger},
8181
query::{Added, AnyOf, Changed, Has, Or, QueryBuilder, QueryState, With, Without},

Diff for: crates/bevy_ecs/src/relationship/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ use log::warn;
2929
/// not already exist, and the "source" entity is automatically added to the [`RelationshipTarget`] collection (this is done via "component hooks").
3030
///
3131
/// A common example of a [`Relationship`] is the parent / child relationship. Bevy ECS includes a canonical form of this via the [`ChildOf`](crate::hierarchy::ChildOf)
32-
/// [`Relationship`] and the [`Children`](crate::hierarchy::Children) [`RelationshipTarget`].
32+
/// [`Relationship`] and the [`ParentOf`](crate::hierarchy::ParentOf) [`RelationshipTarget`].
3333
///
3434
/// [`Relationship`] and [`RelationshipTarget`] should always be derived via the [`Component`] trait to ensure the hooks are set up properly.
3535
///
3636
/// ```
3737
/// # use bevy_ecs::component::Component;
3838
/// # use bevy_ecs::entity::Entity;
3939
/// #[derive(Component)]
40-
/// #[relationship(relationship_target = Children)]
40+
/// #[relationship(relationship_target = ParentOf)]
4141
/// pub struct ChildOf(pub Entity);
4242
///
4343
/// #[derive(Component)]
4444
/// #[relationship_target(relationship = ChildOf)]
45-
/// pub struct Children(Vec<Entity>);
45+
/// pub struct ParentOf(Vec<Entity>);
4646
/// ```
4747
///
4848
/// When deriving [`RelationshipTarget`] you can specify the `#[relationship_target(despawn_descendants)]` attribute to
@@ -52,12 +52,12 @@ use log::warn;
5252
/// # use bevy_ecs::component::Component;
5353
/// # use bevy_ecs::entity::Entity;
5454
/// #[derive(Component)]
55-
/// #[relationship(relationship_target = Children)]
55+
/// #[relationship(relationship_target = ParentOf)]
5656
/// pub struct ChildOf(pub Entity);
5757
///
5858
/// #[derive(Component)]
5959
/// #[relationship_target(relationship = ChildOf, despawn_descendants)]
60-
/// pub struct Children(Vec<Entity>);
60+
/// pub struct ParentOf(Vec<Entity>);
6161
/// ```
6262
pub trait Relationship: Component + Sized {
6363
/// The [`Component`] added to the "target" entities of this [`Relationship`], which contains the list of all "source"

Diff for: crates/bevy_ecs/src/relationship/relationship_query.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
6262
{
6363
self.iter_descendants_depth_first(entity).filter(|entity| {
6464
self.get(*entity)
65-
// These are leaf nodes if they have the `Children` component but it's empty
65+
// These are leaf nodes if they have the `ParentOf` component but it's empty
6666
.map(|children| children.len() == 0)
67-
// Or if they don't have the `Children` component at all
67+
// Or if they don't have the `ParentOf` component at all
6868
.unwrap_or(true)
6969
})
7070
}

Diff for: crates/bevy_ecs/src/system/commands/entity_command.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ pub fn retain<T: Bundle>() -> impl EntityCommand {
254254
///
255255
/// # Note
256256
///
257-
/// This will also despawn any [`Children`](crate::hierarchy::Children) entities, and any other [`RelationshipTarget`](crate::relationship::RelationshipTarget) that is configured
257+
/// This will also despawn any child entities in [`ParentOf`](crate::hierarchy::ParentOf), and any other [`RelationshipTarget`](crate::relationship::RelationshipTarget) that is configured
258258
/// to despawn descendants. This results in "recursive despawn" behavior.
259259
pub fn despawn() -> impl EntityCommand {
260260
#[cfg(feature = "track_location")]

Diff for: crates/bevy_ecs/src/system/commands/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,7 @@ impl<'a> EntityCommands<'a> {
17001700
/// # Note
17011701
///
17021702
/// This will also despawn the entities in any [`RelationshipTarget`](crate::relationship::RelationshipTarget) that is configured
1703-
/// to despawn descendants. For example, this will recursively despawn [`Children`](crate::hierarchy::Children).
1703+
/// to despawn descendants. For example, this will recursively despawn child entities in [`ParentOf`](crate::hierarchy::ParentOf).
17041704
///
17051705
/// # Example
17061706
///
@@ -1740,7 +1740,7 @@ impl<'a> EntityCommands<'a> {
17401740
/// # Note
17411741
///
17421742
/// This will also despawn the entities in any [`RelationshipTarget`](crate::relationship::RelationshipTarget) that are configured
1743-
/// to despawn descendants. For example, this will recursively despawn [`Children`](crate::hierarchy::Children).
1743+
/// to despawn descendants. For example, this will recursively despawn [`ParentOf`](crate::hierarchy::ParentOf).
17441744
pub fn try_despawn(&mut self) {
17451745
self.queue_handled(entity_command::despawn(), error_handler::silent());
17461746
}

Diff for: crates/bevy_ecs/src/world/entity_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2098,7 +2098,7 @@ impl<'w> EntityWorldMut<'w> {
20982098
///
20992099
/// # Note
21002100
///
2101-
/// This will also despawn any [`Children`](crate::hierarchy::Children) entities, and any other [`RelationshipTarget`](crate::relationship::RelationshipTarget) that is configured
2101+
/// This will also despawn any child entities in [`ParentOf`](crate::hierarchy::ParentOf), and any other [`RelationshipTarget`](crate::relationship::RelationshipTarget) that is configured
21022102
/// to despawn descendants. This results in "recursive despawn" behavior.
21032103
///
21042104
/// # Panics

Diff for: crates/bevy_ecs/src/world/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ impl World {
12771277
/// # Note
12781278
///
12791279
/// This will also despawn the entities in any [`RelationshipTarget`](crate::relationship::RelationshipTarget) that is configured
1280-
/// to despawn descendants. For example, this will recursively despawn [`Children`](crate::hierarchy::Children).
1280+
/// to despawn descendants. For example, this will recursively despawn child entities in [`ParentOf`](crate::hierarchy::ParentOf).
12811281
///
12821282
/// ```
12831283
/// use bevy_ecs::{component::Component, world::World};

Diff for: crates/bevy_input_focus/src/tab_navigation.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use bevy_ecs::prelude::ReflectComponent;
2929
use bevy_ecs::{
3030
component::Component,
3131
entity::Entity,
32-
hierarchy::{Children, ChildOf},
32+
hierarchy::{ParentOf, ChildOf},
3333
observer::Trigger,
3434
query::{With, Without},
3535
system::{Commands, Query, Res, ResMut, SystemParam},
@@ -148,12 +148,12 @@ pub enum TabNavigationError {
148148
#[derive(SystemParam)]
149149
pub struct TabNavigation<'w, 's> {
150150
// Query for tab groups.
151-
tabgroup_query: Query<'w, 's, (Entity, &'static TabGroup, &'static Children)>,
151+
tabgroup_query: Query<'w, 's, (Entity, &'static TabGroup, &'static ParentOf)>,
152152
// Query for tab indices.
153153
tabindex_query: Query<
154154
'w,
155155
's,
156-
(Entity, Option<&'static TabIndex>, Option<&'static Children>),
156+
(Entity, Option<&'static TabIndex>, Option<&'static ParentOf>),
157157
Without<TabGroup>,
158158
>,
159159
// Query for parents.

Diff for: crates/bevy_render/src/mesh/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl Plugin for MorphPlugin {
6868
///
6969
/// Only direct children are updated, to fulfill the expectations of glTF spec.
7070
pub fn inherit_weights(
71-
morph_nodes: Query<(&Children, &MorphWeights), (Without<Mesh3d>, Changed<MorphWeights>)>,
71+
morph_nodes: Query<(&ParentOf, &MorphWeights), (Without<Mesh3d>, Changed<MorphWeights>)>,
7272
mut morph_primitives: Query<&mut MeshMorphWeights, With<Mesh3d>>,
7373
) {
7474
for (children, parent_weights) in &morph_nodes {

Diff for: crates/bevy_render/src/view/visibility/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::{
2828

2929
/// User indication of whether an entity is visible. Propagates down the entity hierarchy.
3030
///
31-
/// If an entity is hidden in this way, all [`Children`] (and all of their children and so on) who
31+
/// If an entity is hidden in this way, all children in [`ParentOf`] (and all of their children and so on) who
3232
/// are set to [`Inherited`](Self::Inherited) will also be hidden.
3333
///
3434
/// This is done by the `visibility_propagate_system` which uses the entity hierarchy and
@@ -316,7 +316,7 @@ pub enum VisibilitySystems {
316316
/// Label for [`update_frusta`] in [`CameraProjectionPlugin`](crate::camera::CameraProjectionPlugin).
317317
UpdateFrusta,
318318
/// Label for the system propagating the [`InheritedVisibility`] in a
319-
/// [`ChildOf`] / [`Children`] hierarchy.
319+
/// [`ChildOf`] / [`ParentOf`] hierarchy.
320320
VisibilityPropagate,
321321
/// Label for the [`check_visibility`] system updating [`ViewVisibility`]
322322
/// of each entity and the [`VisibleEntities`] of each view.\
@@ -387,14 +387,14 @@ pub fn update_frusta(
387387

388388
fn visibility_propagate_system(
389389
changed: Query<
390-
(Entity, &Visibility, Option<&ChildOf>, Option<&Children>),
390+
(Entity, &Visibility, Option<&ChildOf>, Option<&ParentOf>),
391391
(
392392
With<InheritedVisibility>,
393393
Or<(Changed<Visibility>, Changed<ChildOf>)>,
394394
),
395395
>,
396396
mut visibility_query: Query<(&Visibility, &mut InheritedVisibility)>,
397-
children_query: Query<&Children, (With<Visibility>, With<InheritedVisibility>)>,
397+
children_query: Query<&ParentOf, (With<Visibility>, With<InheritedVisibility>)>,
398398
) {
399399
for (entity, visibility, parent, children) in &changed {
400400
let is_visible = match visibility {
@@ -428,7 +428,7 @@ fn propagate_recursive(
428428
parent_is_visible: bool,
429429
entity: Entity,
430430
visibility_query: &mut Query<(&Visibility, &mut InheritedVisibility)>,
431-
children_query: &Query<&Children, (With<Visibility>, With<InheritedVisibility>)>,
431+
children_query: &Query<&ParentOf, (With<Visibility>, With<InheritedVisibility>)>,
432432
// BLOCKED: https://github.com/rust-lang/rust/issues/31436
433433
// We use a result here to use the `?` operator. Ideally we'd use a try block instead
434434
) -> Result<(), ()> {

Diff for: crates/bevy_scene/src/scene_spawner.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ impl SceneSpawner {
377377
for (instance_id, parent) in scenes_with_parent {
378378
if let Some(instance) = self.spawned_instances.get(&instance_id) {
379379
for &entity in instance.entity_map.values() {
380-
// Add the `ChildOf` component to the scene root, and update the `Children` component of
380+
// Add the `ChildOf` component to the scene root, and update the `ParentOf` component of
381381
// the scene parent
382382
if !world
383383
.get_entity(entity)
@@ -518,7 +518,7 @@ mod tests {
518518
use bevy_asset::{AssetPlugin, AssetServer, Handle};
519519
use bevy_ecs::{
520520
component::Component,
521-
hierarchy::Children,
521+
hierarchy::ParentOf,
522522
observer::Trigger,
523523
prelude::ReflectComponent,
524524
query::With,
@@ -583,7 +583,7 @@ mod tests {
583583
assert_eq!(scene_component_a.x, 3.0);
584584
assert_eq!(scene_component_a.y, 4.0);
585585
assert_eq!(
586-
app.world().entity(entity).get::<Children>().unwrap().len(),
586+
app.world().entity(entity).get::<ParentOf>().unwrap().len(),
587587
1
588588
);
589589

@@ -598,7 +598,7 @@ mod tests {
598598
assert!(app.world().get_entity(scene_entity).is_err());
599599

600600
// the root entity does not have any children anymore
601-
assert!(app.world().entity(entity).get::<Children>().is_none());
601+
assert!(app.world().entity(entity).get::<ParentOf>().is_none());
602602
}
603603

604604
#[derive(Reflect, Component, Debug, PartialEq, Eq, Clone, Copy, Default)]

0 commit comments

Comments
 (0)