Skip to content

Cloneable Bundles #10907

@viridia

Description

@viridia

What problem does this solve or what need does it fill?

There are cases where I need to clone a bundle, but only if the components in the bundle are also cloneable.

Normally when you insert a bundle, the world takes ownership of the bundle and there is no need for cloning. However, a lot of folks are looking into reactive or dynamic frameworks where the "assembly" or "update" step happens multiple times. This update step might involve updating components, or attaching a copy of the components to a different entity. This means that the template needs to retain ownership of the bundle between updates.

What solution would you like?

What would be the most convenient for me is if Bundle could conditionally implement Clone. This would only happen if all of the components in the bundle are cloneable.

What alternative(s) have you considered?

It is currently possible to do this by inserting components one at a time instead of using bundles, since individual components can implement Clone.

We can also work around this problem by using a closure which generates a copy of the bundle each time; however the resulting code is quite ugly, especially in the case like bevy_mod_picking where the components being inserted also contain closures, so you get closures inside of closures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useX-Needs-SMEThis type of work requires an SME to approve it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions