Skip to content

Support Removing Required Components at Runtime #14927

Closed as not planned
Closed as not planned
@omaskery

Description

@omaskery

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

We are adding the ability to require components in Bevy, this feature request asks for the ability to override this behaviour when it prevents you from customizing third party code.

For example, suppose you're using some hypothetical Bevy provided components & systems:

Suppose there are components:

  • SpecialComponent (which requires Transform),
  • Transform (which requires GlobalTransform), and
  • GlobalTransform.

Suppose there is the system: update_globaltransform_for_specialcomponents_with_transforms.

You're having a great time, until you reach an edge case where your requirements deviate from Bevy's assumptions, so you try to swap out some types:
You create a new component: BetterTransform.
You create a new system: update_globaltransform_for_specialcomponents_with_bettertransforms.

Pre-"Required Components": you would be unable to use bundles that assumed SpecialComponent should use Transform, potentially defining your own new bundles for convenience, but you'd be able to move on and achieve your goals.

In a world with "Required Components": you cannot currently "un-require" Transform from SpecialComponent in 3rd party code (without forking), resulting in this situation:

Your types end up with all of the components: SpecialComponent pulls in Transform, you add BetterTransform, Transform and BetterTransform pull in GlobalTransform.
You end up with two systems trying to compute the GlobalTransform for SpecialComponents:
update_globaltransform_for_specialcomponents_with_transforms, and
update_globaltransform_for_specialcomponents_with_bettertransforms.

What solution would you like?

Currently the required components are authored using an annotation. This feature request proposes that methods be added to Bevy's App type for customizing them dynamically, a hypothetical set of methods:

  • app.add_requires::<DependantComponent, RequiredComponent>();
  • app.remove_requires::<DependantComponent, RequiredComponent>();

(Names bike-sheddable as always!).

These would, as the names hopefully suggest, dynamically (un)register the "required components" relationship between those two types. The annotations in the current implementation would just be a short-hand for automatically registering these relationships.

What alternative(s) have you considered?

Extensive discussion in Discord (the Next Generation Scene/UI Working Group channel), including but not limited to:

  • Not having required components (because BSN might add good enough Nested Scenes to address the need)
  • A full-fledged "provides" system where instead of requiring a component you require some contract that other components provide
  • ???

Effectively, Required Components are going in (soon? today? already?), so we're committed to experimenting with those and learning from it. This feature request effectively acts as a short-term solution to ensure the addition of Required Components doesn't cause a surge in use that prevents customizability.

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsA-TransformTranslations, rotations and scalesC-FeatureA new feature, making something new possibleS-WontfixThis issue is the result of a deliberate design decision, and will not be fixedX-ControversialThere is active debate or serious implications around merging this PR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions