bevy/crates/bevy_ecs/src
SpecificProtagonist 21195a75e6
track_change_detection: Also track spawns/despawns (#16047)
# 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:
```rust
let mut world = World::new();
let entity = world.spawn_empty().id();
println!("spawned by: {}", world.entity(entity).spawned_by());
```
```
spawned by: src/main.rs:5:24
```
Error message (with `track_change_detection`):
```rust
world.despawn(entity);
world.entity(entity);
```
```
thread 'main' panicked at src/main.rs:11:11:
Entity 0v1#4294967296 was despawned by src/main.rs:10:11
```
and without:
```
thread 'main' panicked at src/main.rs:11:11:
Entity 0v1#4294967296 does not exist (enable `track_change_detection` feature for more details)
```
Similar error messages now also exists for `Query::get`,
`World::entity_mut`, `EntityCommands` creation and everything that
causes `B0003`, e.g.
```
error[B0003]: Could not insert a bundle (of type `MaterialMeshBundle<StandardMaterial>`) for entity Entity { index: 7, generation: 1 }, which was despawned by src/main.rs:10:11. See: https://bevyengine.org/learn/errors/#b0003
```

---------

Co-authored-by: kurk070ff <108901106+kurk070ff@users.noreply.github.com>
Co-authored-by: Freya Pines <freya@MacBookAir.lan>
Co-authored-by: Freya Pines <freya@Freyas-MacBook-Air.local>
Co-authored-by: Matty Weatherley <weatherleymatthew@gmail.com>
2024-12-17 04:46:31 +00:00
..
entity track_change_detection: Also track spawns/despawns (#16047) 2024-12-17 04:46:31 +00:00
event Event source location tracking (#16778) 2024-12-12 18:12:53 +00:00
identifier Use en-us locale for typos (#16037) 2024-10-20 18:55:17 +00:00
observer Rename trigger.entity() to trigger.target() (#16716) 2024-12-08 21:55:09 +00:00
query track_change_detection: Also track spawns/despawns (#16047) 2024-12-17 04:46:31 +00:00
reflect track_change_detection: Also track spawns/despawns (#16047) 2024-12-17 04:46:31 +00:00
schedule Update hashbrown to 0.15 (#15801) 2024-12-10 19:45:50 +00:00
storage ✏️ Fix typos across bevy (#16702) 2024-12-08 01:18:39 +00:00
system track_change_detection: Also track spawns/despawns (#16047) 2024-12-17 04:46:31 +00:00
world track_change_detection: Also track spawns/despawns (#16047) 2024-12-17 04:46:31 +00:00
archetype.rs Misc. docs and renames for niche ECS internals (#16786) 2024-12-12 19:24:13 +00:00
batching.rs Fix *most* clippy lints (#15906) 2024-10-14 20:52:35 +00:00
bundle.rs Misc. docs and renames for niche ECS internals (#16786) 2024-12-12 19:24:13 +00:00
change_detection.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
component.rs Descriptive error message for circular required components recursion (#16648) 2024-12-11 01:26:35 +00:00
intern.rs Update hashbrown to 0.15 (#15801) 2024-12-10 19:45:50 +00:00
label.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
lib.rs Rust 1.83, allow -> expect (missing_docs) (#16561) 2024-12-16 23:27:57 +00:00
removal_detection.rs fix: add reflect to SceneInstanceReady and other observers/events (#16018) 2024-10-20 13:51:41 +00:00
result.rs Fallible systems (#16589) 2024-12-05 22:29:06 +00:00
traversal.rs Window picking (#16103) 2024-12-05 21:14:39 +00:00