-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Moving components from one entity to another #15350
Copy link
Copy link
Closed
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleA new feature, making something new possibleC-UsabilityA targeted quality-of-life change that makes Bevy easier to useA targeted quality-of-life change that makes Bevy easier to useD-ComplexQuite challenging from either a design or technical perspective. Ask for help!Quite challenging from either a design or technical perspective. Ask for help!S-Needs-DesignThis issue requires design work to think about how it would best be accomplishedThis issue requires design work to think about how it would best be accomplished
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleA new feature, making something new possibleC-UsabilityA targeted quality-of-life change that makes Bevy easier to useA targeted quality-of-life change that makes Bevy easier to useD-ComplexQuite challenging from either a design or technical perspective. Ask for help!Quite challenging from either a design or technical perspective. Ask for help!S-Needs-DesignThis issue requires design work to think about how it would best be accomplishedThis issue requires design work to think about how it would best be accomplished
What problem does this solve or what need does it fill?
For my reversible systems crate I want to support reversible entity commands that do structural changes.
For example, to create a reversible variant of
EntityCommands::insert, that takes aBundleas an argument, I first have to move the components that would be overwritten out of the entity so I can make this process undoable.BundleInfohas the methods I need to get the relevant ids including required components. However, there is no further API from here on.What solution would you like?
What would work is to move components from one entity to another by id(s). A typed variant should be added there too because it does not exist yet. This is an elegant solution because the data structure of storing untyped components is already there: The ECS storages. This might be useful for other use cases as well.
Each variant should also come with a
_with_requiresvariant like #15026 that has the difference to not construct required components at the target entity but to move them from the source entity as well.Hooks should be triggered by these operations.
Panics should happen if either the source or target entity is missing or at least one
ComponentIdis invalid.Open questions
try_insertthat fail silently?What alternative(s) have you considered?
An alternative is to move the components entirely out of the ECS storage as some kind of blob. However, no such type exists yet as far I can tell. It would require extra work to design this blob, also because it needs to support generating
OwningPtrfor reinsertion.I see no alternative in my untyped context. I could mirror the Bundle trait to create an associated function but that would not work with third-party Bundle implementors that do not implement my trait.
Until a feature like this comes out I consider to require only tuple bundles for my crate's API with further restrictions on the upcoming required components feature. This probably makes the API very panic-happy. 🫤
I see reflection not helping me here as not every component can be reflected.