-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Archetype Invariants #1481
Copy link
Copy link
Open
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleA new feature, making something new possibleC-UsabilityA targeted quality-of-life change that makes Bevy easier to useA targeted quality-of-life change that makes Bevy easier to useS-Needs-GoalThis should have a C-Goal and should not continue until it has oneThis should have a C-Goal and should not continue until it has oneX-Needs-SMEThis type of work requires an SME to approve it.This type of work requires an SME to approve it.
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleA new feature, making something new possibleC-UsabilityA targeted quality-of-life change that makes Bevy easier to useA targeted quality-of-life change that makes Bevy easier to useS-Needs-GoalThis should have a C-Goal and should not continue until it has oneThis should have a C-Goal and should not continue until it has oneX-Needs-SMEThis type of work requires an SME to approve it.This type of work requires an SME to approve it.
Type
Projects
Status
Needs SME Triage
Introduced in #1312. The complete design will be found at RFC #5.
The Basics
An archetype is the set of components that are found together on a single entity. The set of archetypes present in our
Worldis the union of the archetypes of every entity in the world.Archetype invariants are rules that limit which components can coexist, limiting the possible archetypes that can co-occur. Because of the flexible power of
commands.spawnandcommands.insert, the components that an entity could have is unknowable at compile time, preventing us from .We can use this information to allow for more granular component access in ways that would otherwise result in inconsistent runtime behavior, or verify that certain logical rules are followed during execution.
Due to the overhead of verifying these rules against the
World's archetypes, this is likely best done only during debug mode, or perhaps by post-hoc inspection of logs.Use Cases
API for specifying archetype invariants
Primitives:
forbidden(my_bundle): an entities archetype cannot have have the specific combination of components listed in the bundle as a subsetDerived:
inseparable(my_bundle): entities that have either component A or B never occur without each other. Equivalent to combiningA.always_with(B)with the reverse for every pairwise combinationdisjoint(my_bundle): entities can only have at most one component in the bundle. Equivalent to creating aforbiddenarchetype invariant for each pairwise combination