From 28b31c5be90ff1bbdbb3d8387bbc6fd4212b64c1 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Fri, 5 Aug 2022 21:00:36 -0500 Subject: [PATCH] Track whether bundles without sources have transforms in their ancestry, and add transforms if needed. --- src/lib.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 94fe124..6cd1b40 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -287,12 +287,18 @@ fn add_sound_without_source( query: Query<(Entity, Option<&Parent>), (Added, Without)>, parents: Query<&Parent>, sources: Query<&Source>, + transforms: Query<&GlobalTransform>, ) { for (entity, parent) in &query { + let mut has_transform = false; let source = if let Some(parent) = parent { - let mut parent: Option<&Parent> = Some(parent); + has_transform = transforms.get(**parent).is_ok(); let mut target = None; + let mut parent: Option<&Parent> = Some(parent); while let Some(p) = parent { + if !has_transform { + has_transform = transforms.get(**p).is_ok(); + } if sources.get(**p).is_ok() { target = Some(**p); break; @@ -304,7 +310,10 @@ fn add_sound_without_source( None }; if source.is_none() { - commands.entity(entity).insert(Source::default()); + let id = commands.entity(entity).insert(Source::default()).id(); + if has_transform { + commands.entity(id).insert_bundle(TransformBundle::default()); + } } } }