From fb34f6ef122decea4bafe2a0ca3afb4b98df9152 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Sun, 22 Sep 2024 14:46:00 -0500 Subject: [PATCH] Fix issue with adding icons to despawned entities. --- src/sound/icon.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/sound/icon.rs b/src/sound/icon.rs index 83071a6..9c83e42 100644 --- a/src/sound/icon.rs +++ b/src/sound/icon.rs @@ -31,18 +31,20 @@ impl Default for SoundIcon { fn added(mut commands: Commands, icons: Query<(Entity, &SoundIcon), Added>) { for (entity, icon) in &icons { - let buffer = icon.audio.clone(); - let gain = icon.gain; - let pitch = icon.pitch; - let looping = icon.interval.is_none(); - commands.entity(entity).insert(Sound { - audio: buffer, - gain, - pitch, - looping, - paused: true, - ..default() - }); + if let Some(mut commands) = commands.get_entity(entity) { + let buffer = icon.audio.clone(); + let gain = icon.gain; + let pitch = icon.pitch; + let looping = icon.interval.is_none(); + commands.insert(Sound { + audio: buffer, + gain, + pitch, + looping, + paused: true, + ..default() + }); + } } }