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

Replaced EntityCommand Implementation for FnOnce #9604

Merged
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
11 changes: 6 additions & 5 deletions crates/bevy_ecs/src/system/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
self as bevy_ecs,
bundle::Bundle,
entity::{Entities, Entity},
world::{FromWorld, World},
world::{EntityMut, FromWorld, World},
};
use bevy_ecs_macros::SystemParam;
use bevy_utils::tracing::{error, info};
Expand Down Expand Up @@ -805,12 +805,13 @@ impl<'w, 's, 'a> EntityCommands<'w, 's, 'a> {
///
/// ```
/// # use bevy_ecs::prelude::*;
/// # use bevy_ecs::world::EntityMut;
/// # fn my_system(mut commands: Commands) {
/// commands
/// .spawn_empty()
/// // Closures with this signature implement `EntityCommand`.
/// .add(|id: Entity, world: &mut World| {
/// println!("Executed an EntityCommand for {id:?}");
/// .add(|entity: EntityMut| {
/// println!("Executed an EntityCommand for {:?}", entity.id());
/// });
/// # }
/// # bevy_ecs::system::assert_is_system(my_system);
Expand Down Expand Up @@ -848,10 +849,10 @@ where

impl<F> EntityCommand for F
where
F: FnOnce(Entity, &mut World) + Send + 'static,
F: FnOnce(EntityMut) + Send + 'static,
{
fn apply(self, id: Entity, world: &mut World) {
self(id, world);
self(world.entity_mut(id));
}
}

Expand Down