-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Required Components #7272
Description
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.