-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 CloneBundle command #3820
Add CloneBundle command #3820
Conversation
The other big part of this design that you haven't outlined yet is a blanket impl for Clone on Bundle, if and only if all of the underlying component types are |
62084ac
to
c2edfb2
Compare
This is a critical building block for #1515. |
/// # use bevy_ecs::prelude::*; | ||
/// # | ||
/// # #[derive(Component, Clone)] | ||
/// # struct Infected; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be much better motivated if it stored a value. Perhaps Infected{remaining_duration: Duration}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alice-i-cecile At moment I've followed the other examples and hidden the Component
in use (see remove
/remove_bundle
example). Just to clarify: you'd like me to un-#
this and give it a field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple, useful, correct. I have a few nits about the docs to improve clarity.
/// # struct Dummy; | ||
/// # | ||
/// # #[derive(Bundle, Clone)] | ||
/// # struct Characteristics { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO we should store multiple actual value-ful components here rather than fussing with Dummy
. Just toss in strength / dexterity / intelligence perhaps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once @alice-i-cecile’s few nits are fixed this looks good to me!
06b6a8e
to
f46816c
Compare
Unsurprisingly, I think you should add |
4e4e6af
to
9f1577e
Compare
This may have occurred due to system order ambiguity, or if the spawning system has multiple command buffers", std::any::type_name::<T>(), self.source); | ||
}; | ||
|
||
let bundle = if let Some(some) = source_mut.remove_bundle::<T>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will trigger "removed events" (in RemovedComponents
) for each component in the bundle, which is undesirable for a clone operation.
} else { | ||
return; | ||
}; | ||
source_mut.insert_bundle(bundle.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will trigger "added" and "changed" events for each component in the bundle, which is undesirable for a clone operation.
The API and docs are reasonable quality. Fixing the implementation is beyond me - waiting for an expert to come along and ressurect this. |
Objective
Cloning one component from an entity to another entity is a common operation. It would make sense if this was supported out the box.
Solution
Create a
clone_bundle
API onEntityCommands
which results in aCloneBundle
command. TheCloneBundle
command peforms aEntityRef::get_bundle::<T>
on thesource
entity, clones that provided reference, and then performsEntityMut::insert_bundle::<T>
onto thetarget
entity.Notes
Similar to #3717