mirror of
https://github.com/bevyengine/bevy
synced 2025-02-17 22:48:38 +00:00
Fix leftover references to children when despawning audio entities (#12407)
# Objective Fixes #12402 ## Solution Use `despawn_recursive` instead of `despawn` for despawning `PlaybackMode::Despawn` audio. ## Migration Guide `PlaybackSettings::DESPAWN` (`PlaybackMode::Despawn`) now despawns the audio entity's children as well. If you were relying on the previous behavior, you may be able to use `PlaybackMode::Remove`, or you may need to use `PlaybackMode::Once` and manage your audio component lifecycle manually.
This commit is contained in:
parent
b3655a3601
commit
c9e32858d7
3 changed files with 5 additions and 3 deletions
|
@ -13,6 +13,7 @@ keywords = ["bevy"]
|
||||||
bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
|
bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
|
||||||
bevy_asset = { path = "../bevy_asset", version = "0.14.0-dev" }
|
bevy_asset = { path = "../bevy_asset", version = "0.14.0-dev" }
|
||||||
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" }
|
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" }
|
||||||
|
bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.14.0-dev" }
|
||||||
bevy_math = { path = "../bevy_math", version = "0.14.0-dev" }
|
bevy_math = { path = "../bevy_math", version = "0.14.0-dev" }
|
||||||
bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [
|
bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [
|
||||||
"bevy",
|
"bevy",
|
||||||
|
|
|
@ -37,7 +37,7 @@ pub enum PlaybackMode {
|
||||||
Once,
|
Once,
|
||||||
/// Repeat the sound forever.
|
/// Repeat the sound forever.
|
||||||
Loop,
|
Loop,
|
||||||
/// Despawn the entity when the sound finishes playing.
|
/// Despawn the entity and its children when the sound finishes playing.
|
||||||
Despawn,
|
Despawn,
|
||||||
/// Remove the audio components from the entity, when the sound finishes playing.
|
/// Remove the audio components from the entity, when the sound finishes playing.
|
||||||
Remove,
|
Remove,
|
||||||
|
|
|
@ -4,6 +4,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use bevy_asset::{Asset, Assets, Handle};
|
use bevy_asset::{Asset, Assets, Handle};
|
||||||
use bevy_ecs::{prelude::*, system::SystemParam};
|
use bevy_ecs::{prelude::*, system::SystemParam};
|
||||||
|
use bevy_hierarchy::DespawnRecursiveExt;
|
||||||
use bevy_math::Vec3;
|
use bevy_math::Vec3;
|
||||||
use bevy_transform::prelude::GlobalTransform;
|
use bevy_transform::prelude::GlobalTransform;
|
||||||
use bevy_utils::tracing::warn;
|
use bevy_utils::tracing::warn;
|
||||||
|
@ -253,12 +254,12 @@ pub(crate) fn cleanup_finished_audio<T: Decodable + Asset>(
|
||||||
) {
|
) {
|
||||||
for (entity, sink) in &query_nonspatial_despawn {
|
for (entity, sink) in &query_nonspatial_despawn {
|
||||||
if sink.sink.empty() {
|
if sink.sink.empty() {
|
||||||
commands.entity(entity).despawn();
|
commands.entity(entity).despawn_recursive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (entity, sink) in &query_spatial_despawn {
|
for (entity, sink) in &query_spatial_despawn {
|
||||||
if sink.sink.empty() {
|
if sink.sink.empty() {
|
||||||
commands.entity(entity).despawn();
|
commands.entity(entity).despawn_recursive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (entity, sink) in &query_nonspatial_remove {
|
for (entity, sink) in &query_nonspatial_remove {
|
||||||
|
|
Loading…
Add table
Reference in a new issue