bevy/crates
Illiux eebc92a7d4
Make scene handling of entity references robust (#7335)
# Objective

- Handle dangling entity references inside scenes
- Handle references to entities with generation > 0 inside scenes
- Fix a latent bug in `Parent`'s `MapEntities` implementation, which
would, if the parent was outside the scene, cause the scene to be loaded
into the new world with a parent reference potentially pointing to some
random entity in that new world.
- Fixes #4793 and addresses #7235 

## Solution

- DynamicScenes now identify entities with a `Entity` instead of a u32,
therefore including generation
- `World` exposes a new `reserve_generations` function that despawns an
entity and advances its generation by some extra amount.
- `MapEntities` implementations have a new `get_or_reserve` function
available that will always return an `Entity`, establishing a new
mapping to a dead entity when the entity they are called with is not in
the `EntityMap`. Subsequent calls with that same `Entity` will return
the same newly created dead entity reference, preserving equality
semantics.
- As a result, after loading a scene containing references to dead
entities (or entities otherwise outside the scene), those references
will all point to different generations on a single entity id in the new
world.

---

## Changelog

### Changed
- In serialized scenes, entities are now identified by a u64 instead of
a u32.
- In serialized scenes, components with entity references now have those
references serialize as u64s instead of structs.
### Fixed
- Scenes containing components with entity references will now
deserialize and add to a world reliably.

## Migration Guide

- `MapEntities` implementations must change from a `&EntityMap`
parameter to a `&mut EntityMapper` parameter and can no longer return a
`Result`. Finally, they should switch from calling `EntityMap::get` to
calling `EntityMapper::get_or_reserve`.

---------

Co-authored-by: Nicola Papale <nicopap@users.noreply.github.com>
2023-05-01 15:49:27 +00:00
..
bevy_a11y Suppress the clippy::type_complexity lint (#8313) 2023-04-06 21:27:36 +00:00
bevy_animation Fixed several missing links in docs. (#8117) 2023-04-23 17:28:36 +00:00
bevy_app Re-add the "frame" span for tracy comparisons (#8362) 2023-04-25 14:56:05 +00:00
bevy_asset bevy_asset: Add LoadContext::get_handle_untyped (#8470) 2023-04-25 19:32:34 +00:00
bevy_audio Ability to set a Global Volume (#7706) 2023-04-10 14:08:43 +00:00
bevy_core Just print out name string, not the entire Name struct (#8494) 2023-04-26 20:00:03 +00:00
bevy_core_pipeline Updated to wgpu 0.16.0, wgpu-hal 0.16.0 and naga 0.12.0 (#8446) 2023-04-26 15:34:23 +00:00
bevy_derive Suppress the clippy::type_complexity lint (#8313) 2023-04-06 21:27:36 +00:00
bevy_diagnostic Suppress the clippy::type_complexity lint (#8313) 2023-04-06 21:27:36 +00:00
bevy_dylib Suppress the clippy::type_complexity lint (#8313) 2023-04-06 21:27:36 +00:00
bevy_dynamic_plugin Suppress the clippy::type_complexity lint (#8313) 2023-04-06 21:27:36 +00:00
bevy_ecs Make scene handling of entity references robust (#7335) 2023-05-01 15:49:27 +00:00
bevy_ecs_compile_fail_tests Fix 1.69 CI clippy lints (#8450) 2023-04-20 16:51:21 +00:00
bevy_encase_derive Suppress the clippy::type_complexity lint (#8313) 2023-04-06 21:27:36 +00:00
bevy_gilrs Add gamepad rumble support to bevy_input (#8398) 2023-04-24 15:28:53 +00:00
bevy_gizmos Add a bounding box gizmo (#8468) 2023-04-24 15:23:06 +00:00
bevy_gltf Add support for custom glTF vertex attributes. (#5370) 2023-04-24 14:20:13 +00:00
bevy_hierarchy Make scene handling of entity references robust (#7335) 2023-05-01 15:49:27 +00:00
bevy_input Add gamepad rumble support to bevy_input (#8398) 2023-04-24 15:28:53 +00:00
bevy_internal make glsl and spirv support optional (#8491) 2023-04-25 19:30:48 +00:00
bevy_log add a feature for memory tracing with tracy (#8272) 2023-04-17 16:04:46 +00:00
bevy_macro_utils Simplify world schedule methods (#8403) 2023-04-19 19:48:35 +00:00
bevy_math Suppress the clippy::type_complexity lint (#8313) 2023-04-06 21:27:36 +00:00
bevy_mikktspace Suppress the clippy::type_complexity lint (#8313) 2023-04-06 21:27:36 +00:00
bevy_pbr Updated to wgpu 0.16.0, wgpu-hal 0.16.0 and naga 0.12.0 (#8446) 2023-04-26 15:34:23 +00:00
bevy_ptr Fixed several missing links in docs. (#8117) 2023-04-23 17:28:36 +00:00
bevy_reflect bevy_reflect: Better proxies (#6971) 2023-04-26 12:17:46 +00:00
bevy_reflect_compile_fail_tests Fix 1.69 CI clippy lints (#8450) 2023-04-20 16:51:21 +00:00
bevy_render Make scene handling of entity references robust (#7335) 2023-05-01 15:49:27 +00:00
bevy_scene Make scene handling of entity references robust (#7335) 2023-05-01 15:49:27 +00:00
bevy_sprite Updated to wgpu 0.16.0, wgpu-hal 0.16.0 and naga 0.12.0 (#8446) 2023-04-26 15:34:23 +00:00
bevy_tasks Fixed several missing links in docs. (#8117) 2023-04-23 17:28:36 +00:00
bevy_text Fix panic when using debug_asset_server (#8485) 2023-04-25 10:11:11 +00:00
bevy_time Fix timer with zero duration (#8467) 2023-04-24 14:32:42 +00:00
bevy_transform Add a bounding box gizmo (#8468) 2023-04-24 15:23:06 +00:00
bevy_ui MeasureFunc improvements (#8402) 2023-05-01 15:40:53 +00:00
bevy_utils Simplify world schedule methods (#8403) 2023-04-19 19:48:35 +00:00
bevy_window Make scene handling of entity references robust (#7335) 2023-05-01 15:49:27 +00:00
bevy_winit Fixed several missing links in docs. (#8117) 2023-04-23 17:28:36 +00:00