Skip to content

Commit cb07eff

Browse files
committed
Add move_from/move_bundle_from
1 parent e75ad5b commit cb07eff

File tree

1 file changed

+28
-2
lines changed
  • crates/bevy_ecs/src/system/commands

1 file changed

+28
-2
lines changed

crates/bevy_ecs/src/system/commands/mod.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ impl<'w, 's, 'a> EntityCommands<'w, 's, 'a> {
512512
self
513513
}
514514

515-
/// Moves a [`Bundle`] from the entity to another.
515+
/// Moves a [`Bundle`] to a target entity.
516516
///
517517
/// # Example
518518
///
@@ -552,7 +552,7 @@ impl<'w, 's, 'a> EntityCommands<'w, 's, 'a> {
552552
self
553553
}
554554

555-
/// Moves a [`Component`] from the entity to another.
555+
/// Moves a [`Component`] to a target entity.
556556
///
557557
/// # Example
558558
///
@@ -575,6 +575,32 @@ impl<'w, 's, 'a> EntityCommands<'w, 's, 'a> {
575575
self.move_bundle_to::<(C,)>(target)
576576
}
577577

578+
/// Moves a [`Bundle`] from a source entity.
579+
///
580+
/// See [`move_bundle_to`](EntityCommands::move_bundle_to).
581+
pub fn move_bundle_from<T: Bundle>(&mut self, source: Entity) -> &mut Self {
582+
assert!(
583+
self.commands.entities.contains(self.entity),
584+
"Attempting to move bundle {:?} from entity {:?} to entity {:?}, which doesn't exist.",
585+
std::any::type_name::<T>(),
586+
source,
587+
self.entity
588+
);
589+
self.commands.add(MoveBundleTo::<T> {
590+
source,
591+
target: self.entity,
592+
_bundle: PhantomData,
593+
});
594+
self
595+
}
596+
597+
/// Moves a [`Component`] from a source entity.
598+
///
599+
/// See [`move_to`](EntityCommands::move_to).
600+
pub fn move_from<C: Component>(&mut self, source: Entity) -> &mut Self {
601+
self.move_bundle_from::<(C,)>(source)
602+
}
603+
578604
/// Despawns the entity.
579605
///
580606
/// See [`World::despawn`] for more details.

0 commit comments

Comments
 (0)