Observers should not use Entity::PLACEHOLDER
#16029
Labels
A-ECS
Entities, components, systems, and events
C-Code-Quality
A section of code that is hard to understand or change
C-Usability
A targeted quality-of-life change that makes Bevy easier to use
D-Modest
A "normal" level of difficulty; suitable for simple features or challenging fixes
S-Ready-For-Implementation
This issue is ready for an implementation PR. Go for it!
Milestone
What problem does this solve or what need does it fill?
As described in the docs for
Trigger::entity
, observers can be triggered by a specific entity, or by no specific entity at all.Rather than returning and storing an
Option
here, we useEntity::PLACEHOLDER
.This is unidiomatic and unclear, and makes it very hard to robustly handle this case.
In Rust,
Option
or other enums is the correct way to handle this, not special-cased values.This is especially true since
Option<Entity>
is niched and doesn't even take up any additional memory.What solution would you like?
Replace all uses of
Entity::PLACEHOLDER
in observers code with anOption<Entity>
.What alternative(s) have you considered?
We could use a custom enum here instead, but I think that an option is sufficiently clear.
Additional context
This was added as part of #10839
The text was updated successfully, but these errors were encountered: