Skip to content
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

Add ChildBuilder::commands method #2448

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 31 additions & 0 deletions crates/bevy_transform/src/hierarchy/child_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,37 @@ impl<'a, 'b> ChildBuilder<'a, 'b> {
self.push_children.parent
}

/// Return a mutable reference to the [`Commands`] the `ChildBuilder` was constructed with.
///
/// Calling [`spawn`][Commands::spawn] or [`spawn_bundle`][Commands::spawn_bundle] on the
/// returned value will **not** insert the parent and children components.
Comment on lines +93 to +94
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a footgun waiting to happen...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a footgun on the already-present add_commands method.

///
/// # Example
///
/// ```
/// # use bevy_ecs::prelude::*;
/// # use bevy_transform::components::{Transform, GlobalTransform};
/// # use bevy_transform::hierarchy::BuildChildren;
/// struct ImportantLocation(Entity);
///
/// fn setup_locations(mut commands: Commands) {
/// commands.spawn()
/// .insert(Transform::from_xyz(1.0, 0.0, 0.0))
/// .insert(GlobalTransform::default())
/// .with_children(|parent| {
/// let entity = parent.spawn()
/// .insert(Transform::from_xyz(1.0, 0.0, 0.0))
/// .insert(GlobalTransform::default())
/// .id();
///
/// parent.commands().insert_resource(ImportantLocation(entity));
/// });
/// }
/// ```
pub fn commands(&mut self) -> &mut Commands<'a> {
self.commands
}

pub fn add_command<C: Command + 'static>(&mut self, command: C) -> &mut Self {
self.commands.add(command);
self
Expand Down