Reduce implicit defaults by requiring more components #504
Labels
C-Code-Quality
Improvements to code readability, maintainability, or best practices
C-Enhancement
New feature or request
X-Contentious
There are nontrivial implications that should be thought through
For Bevy 0.15, which will have required components.
Objective
Currently, Avian has implied defaults for numerous components. This means that when a component doesn't exist on an entity, a default value or behavior is used in its place. Examples include:
CollisionLayers
Friction
Restitution
Dominance
GravityScale
SpeculativeMargin
and probably many more.
It seems like these kinds of implied default values for components should generally be discouraged. Quoting Cart (the Project Lead of Bevy) on Discord, in the context of UI:
along with:
This was initially in the context of UI, so I asked if this should also be considered a "best practice" that the ecosystem as a whole should follow (along with some component examples), to which the response was:
In summary, it seems like there is quite a clear preference (from Cart) towards not having implied default values for components. In practice, this would just mean having more components automatically inserted via the required components functionality coming in Bevy 0.15.
It didn't seem like there was full consensus on this in general though, and it's not entirely clear which components count as being a "property" of an entity. I'm personally not fully sold on requiring all of the components listed earlier in cases where the component is mostly intended for opting out of default behavior, or just otherwise very niche (e.g.
GravityScale
andSpeculativeMargin
), but we can probably decide on a case-by-case basis.Pros
CollisionLayers
. No need forOption<&CollisionLayers>
with a default fallback.Option<T>
in many queries, reducing branching.Cons
Option<T>
, getting rid of implied defaults is good, but what about normal queries withT
? Previously, queries skipped entities withoutT
, but nowT
is added for all entities that have components that require it, so queries iterate over all of them.The text was updated successfully, but these errors were encountered: