Fix issue with adding icons to despawned entities.

This commit is contained in:
Nolan Darilek 2024-09-22 14:46:00 -05:00
parent 015e98d419
commit fb34f6ef12

View File

@ -31,18 +31,20 @@ impl Default for SoundIcon {
fn added(mut commands: Commands, icons: Query<(Entity, &SoundIcon), Added<SoundIcon>>) { fn added(mut commands: Commands, icons: Query<(Entity, &SoundIcon), Added<SoundIcon>>) {
for (entity, icon) in &icons { for (entity, icon) in &icons {
let buffer = icon.audio.clone(); if let Some(mut commands) = commands.get_entity(entity) {
let gain = icon.gain; let buffer = icon.audio.clone();
let pitch = icon.pitch; let gain = icon.gain;
let looping = icon.interval.is_none(); let pitch = icon.pitch;
commands.entity(entity).insert(Sound { let looping = icon.interval.is_none();
audio: buffer, commands.insert(Sound {
gain, audio: buffer,
pitch, gain,
looping, pitch,
paused: true, looping,
..default() paused: true,
}); ..default()
});
}
} }
} }