-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
track_change_detection: Also track spawns/despawns #16047
base: main
Are you sure you want to change the base?
track_change_detection: Also track spawns/despawns #16047
Conversation
crates/bevy_ecs/src/query/error.rs
Outdated
Self::NoSuchEntity(entity, world) => { | ||
#[cfg(feature = "track_change_detection")] | ||
{ | ||
if let Some(location) = world.entities().get_entity_spawned_despawned_by(entity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really cool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice change, I think this philosophy should be extended to more areas of Bevy too (e.g., Component
s). However, there is a safety comment which I believe this change violates. Either the PR needs to be amended to satisfy the invariant, or a SAFETY
comment should be added to the field to indicate why it is safe.
crates/bevy_ecs/src/query/error.rs
Outdated
} | ||
#[cfg(not(feature = "track_change_detection"))] | ||
{ | ||
write!(f, "The entity {entity} does not exist") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nice to include a hint here to enable track_change_detection
for a more detailed error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea; implemented. Should I note in the feature description (in Cargo.toml
) that this feature has a perf impact so people don't ship with it on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's a good idea. And like the tracing
filter level features, we should include a note saying library authors should not enable this feature on their published crates, as it removes the ability for end-users to choose themselves.
# Objective `flush_and_reserve_invalid_assuming_no_entities` was made for the old rendering world (which was reset every frame) and is usused since the 0.15 retained rendering world, but wasn't removed yet. It is pub, but is undocumented apart from the safety comment. ## Solution Remove `flush_and_reserve_invalid_assuming_no_entities` and the safety invariants this method required for `EntityMeta`, `EntityLocation`, `TableId` and `TableRow`. This reduces the amount of unsafe code & safety invariants and makes #16047 easier. ## Alternatives - Document `flush_and_reserve_invalid_assuming_no_entities` and keep it unchanged - Document `flush_and_reserve_invalid_assuming_no_entities` and change it to be based on `EntityMeta::INVALID` ## Migration Guide - exchange `Entities::flush_and_reserve_invalid_assuming_no_entities` for `reserve` and `flush_as_invalid` and notify us if that's insufficient --------- Co-authored-by: Benjamin Brienen <[email protected]>
451ffc3
to
85dc8ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic. I've marked this as ready for review.
Objective
Expand
track_change_detection
feature to also track entity spawns and despawns. Use this to create better error messages.Solution
Adds
Entities::entity_get_spawned_or_despawned_by
as well as{all entity reference types}::spawned_by
.This also removes the deprecated
get_many_entities_mut
& co (and therefore can't land in 0.15) because we don't yet have no Polonius.Testing
Added a test that checks that the locations get updated and these updates are ordered correctly vs hooks & observers.
Showcase
Access location:
Error message (with
track_change_detection
):and without:
Similar error messages now also exists for
Query::get
,World::entity_mut
,EntityCommands
creation and everything that causesB0003
, e.g.