Skip to content

Required Components #7272

@Pietrek14

Description

@Pietrek14

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

Some components don't make sense without some other components, e.g. Transform without GlobalTransform, Visibility without CalculatedVisibility or Interaction without Node. We don't really have a way of communicating it other than putting it in a doc-comment. I feel like this is an unelegant and bug-prone solution.

What solution would you like?

I would like to have a #[require] attribute, applicable to a component A, taking in another component B as an argument, that would signal that every entity containing the component A has to also contain the component B. Then, when adding the component A to an entity, Bevy could perform a check to see if the component B is already on the entity (or is being added at the same time as component A) and if it's not, a panic would occur. Such a feature is implemented in Unity and I'm missing it in Bevy.

Further down the line we could implement compile-time checks for Bundles to see if they contain all the required components. Similarly we could check if a Query has redundant With filters.

What alternative(s) have you considered?

We could leave it as is and believe the user to remember to add the necessary components. User could also add a system checking if there are any entities in the world with one component and not the other, although it would probably be much less performant.

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 useS-Needs-ReviewNeeds reviewer attention (from anyone!) to move forwardX-BlessedHas a large architectural impact or tradeoffs, but the design has been endorsed by decision makers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions