Skip to content

Commit

Permalink
Added docs on how Parent component is affected by BuildChildren m…
Browse files Browse the repository at this point in the history
…ethods. (#17205)

`BuildChildren` docs didn't specify how the children's `Parent`
components are changed, which is now fixed.
Fixes #16526.
  • Loading branch information
AlephCubed authored Jan 7, 2025
1 parent f26af8f commit 9f18fa6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions crates/bevy_hierarchy/src/child_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ pub trait BuildChildren {

/// Spawns the passed bundle and adds it to this entity as a child.
///
/// The bundle's [`Parent`] component will be updated to the new parent.
///
/// For efficient spawning of multiple children, use [`with_children`].
///
/// [`with_children`]: BuildChildren::with_children
Expand All @@ -256,6 +258,8 @@ pub trait BuildChildren {
/// Pushes children to the back of the builder's children. For any entities that are
/// already a child of this one, this method does nothing.
///
/// The children's [`Parent`] component will be updated to the new parent.
///
/// If the children were previously children of another parent, that parent's [`Children`] component
/// will have those children removed from its list. Removing all children from a parent causes its
/// [`Children`] component to be removed from the entity.
Expand All @@ -267,6 +271,8 @@ pub trait BuildChildren {

/// Inserts children at the given index.
///
/// The children's [`Parent`] component will be updated to the new parent.
///
/// If the children were previously children of another parent, that parent's [`Children`] component
/// will have those children removed from its list. Removing all children from a parent causes its
/// [`Children`] component to be removed from the entity.
Expand All @@ -276,13 +282,17 @@ pub trait BuildChildren {
/// Panics if any of the children are the same as the parent.
fn insert_children(&mut self, index: usize, children: &[Entity]) -> &mut Self;

/// Removes the given children
/// Removes the given children.
///
/// The removed children will have their [`Parent`] component removed.
///
/// Removing all children from a parent causes its [`Children`] component to be removed from the entity.
fn remove_children(&mut self, children: &[Entity]) -> &mut Self;

/// Adds a single child.
///
/// The child's [`Parent`] component will be updated to the new parent.
///
/// If the child was previously the child of another parent, that parent's [`Children`] component
/// will have the child removed from its list. Removing all children from a parent causes its
/// [`Children`] component to be removed from the entity.
Expand All @@ -292,11 +302,13 @@ pub trait BuildChildren {
/// Panics if the child is the same as the parent.
fn add_child(&mut self, child: Entity) -> &mut Self;

/// Removes all children from this entity. The [`Children`] component will be removed if it exists, otherwise this does nothing.
/// Removes all children from this entity. The [`Children`] component and the children's [`Parent`] component will be removed.
/// If the [`Children`] component is not present, this has no effect.
fn clear_children(&mut self) -> &mut Self;

/// Removes all current children from this entity, replacing them with the specified list of entities.
///
/// The added children's [`Parent`] component will be updated to the new parent.
/// The removed children will have their [`Parent`] component removed.
///
/// # Panics
Expand Down

0 comments on commit 9f18fa6

Please sign in to comment.