bevy/crates/bevy_scene/src
Charles Bournhonesque afff818e5c
Update the Children component of the parent entity when a scene gets deleted (#12710)
# Objective

- A scene usually gets created using the `SceneBundle` or
`DynamicSceneBundle`. This means that the scene's entities get added as
children of the root entity (the entity on which the `SceneBundle` gets
added)
- When the scene gets deleted using the `SceneSpawner`, the scene's
entities are deleted, but the `Children` component of the root entity
doesn't get updated. This means that the hierarchy becomes unsound, with
Children linking to non-existing components.

## Solution

- Update the `despawn_sync` logic to also update the `Children` from any
parents of the scene, if there are any
- Adds a test where a Scene gets despawned and checks for dangling
Children references on the parent. The test fails on `main` but works
here.

## Alternative implementations

- One option could be to add a `parent: Option<Entity>` on the
[InstanceInfo](df15cd7dcc/crates/bevy_scene/src/scene_spawner.rs (L27))
struct that tracks if the SceneInstance was added as a child of a root
entity
2024-03-29 13:13:32 +00:00
..
bundle.rs Update the Children component of the parent entity when a scene gets deleted (#12710) 2024-03-29 13:13:32 +00:00
dynamic_scene_builder.rs Make builder types take and return Self (#10001) 2023-10-09 19:46:17 +00:00
dynamic_scene.rs Fix TypeRegistry use in dynamic scene (#12715) 2024-03-28 03:09:31 +00:00
lib.rs Forbid unsafe in most crates in the engine (#12684) 2024-03-27 03:30:08 +00:00
scene_filter.rs Make builder types take and return Self (#10001) 2023-10-09 19:46:17 +00:00
scene_loader.rs Fix TypeRegistry use in dynamic scene (#12715) 2024-03-28 03:09:31 +00:00
scene_spawner.rs Update the Children component of the parent entity when a scene gets deleted (#12710) 2024-03-29 13:13:32 +00:00
scene.rs Replace FromWorld requirement on ReflectResource and reflect Resource for State<S> (#12136) 2024-02-27 15:49:39 +00:00
serde.rs Fix TypeRegistry use in dynamic scene (#12715) 2024-03-28 03:09:31 +00:00