Closed
Description
Problem
Marker components (zero-sized structs used only for filtering) are very useful and natural. However, they have a few problems that make them hard to use in the engine. From @cart in #3796:
- Marker components have a "visual editor" problem. With a standard "display current entity components" approach, marker components aren't discoverable. You need to know that a given entity supports them. With the current bool approach, Visibility would always show up on supported entities in the editor with a toggle-able is_visible widget.
- There's also the general "discoverability" problem: marker components that aren't part of the default bundle will have no direct correlation to the entities that support them. Ex: the NotShadowReceiver marker component suffers from this problem.
Potential Solutions
- Don't use marker components in the engine (or don't use them for core elements).
i. Query filters are faster than manually checking values. This is important for e.g. core rendering algorithms.
ii. Query filters are less blocking than manually checking values.
iii. Query filters are clearer than manually checking values, as the information is encoded in the function signature.
iv. The issues raised above will also apply to end user games, so this is not really a solution. - Marker components "enable behavior" by convention:
ShadowCaster
, notNotShadowCaster
.
i. Improves discoverability: most relevant behaviors will be enabled by default.
ii. Improves clarity by avoiding double-negative reasoning.
iii. Will very slightly increase overhead in cases where the behavior is a default.
iv. Does not solve visual editor problem, as there's no way to tie entities back to their original bundles.
v. Does not fully solve discoverability problem, as not all interesting behavior is on-by-default. - Bundles with optional components (Bundles with optional components #2157).
i. Solves the general discoverability problem, but only for plugin/engine components.
ii. Does not solve the visual editor problem, since we don't know which bundles an entity is made up of.
iii. May have non-trivial performance overhead for spawning entities with optional bundle fields.
iv. Almost certainly requires Make a dynamically applicable version ofBundle
#3694 to be merged. - Tool to detect which bundles an entity contains (Label entities by the component bundles they have for clearer inspection #1958).
i. More powerful with 2 and 3, solving their visual editor problem.
ii. Store this information at entity creation time, or compare the components to a registered list of bundles. - Leverage archetype invariants (Archetype Invariants #1481) and inspect "related components" at the component level.
i. Hard to display in the docs.rs docs, unless by some miracle we can do this all at a type level.
ii. Provides a clear, general mechanism for discovery in both cases.
iii. Discoverability is user-extensible. - Create a tool that shows which other components a component is found with in queries.
i. Like 5, but way easier and automatic.