Track whether bundles without sources have transforms in their ancestry, and add transforms if needed.

This commit is contained in:
Nolan Darilek 2022-08-05 21:00:36 -05:00
parent b443390d62
commit 28b31c5be9

View File

@ -287,12 +287,18 @@ fn add_sound_without_source(
query: Query<(Entity, Option<&Parent>), (Added<Sound>, Without<Source>)>,
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());
}
}
}
}