Skip to content

Access data from removed components #1655

@alice-i-cecile

Description

@alice-i-cecile

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

When removing components (or despawning entities with those components), we often want to perform cleanup. Unfortunately, this work typically requires data from that removed component, rather than just the entity that was returned. See our example for the current behavior.

What solution would you like?

Store the Removed data in a special "purgatory" sparse set that we keep around until the frame-after-next, using the same double-buffer strategy as Events.

What alternative(s) have you considered?

Write custom commands to remove components that require cleanup, like despawn_recursive. This is hard to extend though and forces the user to not clean stuff up.

Always emit a "to despawn" event, and then clean things up before the data is lost by making sure that the cleanup systems run first.

Users manually archive and then access the components that they need to access once removed.

Additional context

Relevant to how we despawn entities in a parent-child hierarchy, e.g. despawn_recursive.

We will need to do the same thing with Resources as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions