mirror of
https://github.com/bevyengine/bevy
synced 2024-12-20 18:13:10 +00:00
da4e7769ad
# Objective Oftentimes, users will store an entity on a component or resource. To make this component/resource `Default`-able, they might initialize it with `Entity::PLACEHOLDER`. This is sometimes done to avoid the need for an `Option<Entity>`, especially if it complicates other logic. For example, it's used in this `Selection` resource to denote "no selection": ```rust #[derive(Resource, Debug)] struct Selection(Entity); impl Default for Selection { fn default() -> Self { Self(Entity::PLACEHOLDER) } } ``` The problem is that if we try to `Debug` the current `Selection`, we get back: `4294967295v1#8589934591`. It's not immediately obvious whether or not the entity is an actual entity or the placeholder. Now while it doesn't take long to realize that this is in fact just the value of `Entity::PLACEHOLDER`, it would be a lot clearer if this was made explicit, especially for these particular use cases. ## Solution This PR makes the `Debug` and `Display` impls for `Entity` return `PLACEHOLDER` for the `Entity::PLACEHOLDER` constant. ~~Feel free to bikeshed the actual value returned here. I think `PLACEHOLDER` on its own could work too.~~ Swapped to `PLACEHOLDER` from `Entity::PLACEHOLDER`. ## Testing You can test locally by running: ``` cargo test --package bevy_ecs ``` --- ## Migration Guide The `Debug` and `Display` impls for `Entity` now return `PLACEHOLDER` for the `Entity::PLACEHOLDER` constant. If you had any code relying on these values, you may need to account for this change. |
||
---|---|---|
.. | ||
entity | ||
event | ||
identifier | ||
observer | ||
query | ||
reflect | ||
schedule | ||
storage | ||
system | ||
world | ||
archetype.rs | ||
batching.rs | ||
bundle.rs | ||
change_detection.rs | ||
component.rs | ||
intern.rs | ||
label.rs | ||
lib.rs | ||
removal_detection.rs | ||
traversal.rs |