Skip to content

Commit a6671d7

Browse files
authored
fix: avoid race condition when spawning animated scenes with colliders (#101)
Unclear why this was triggering a race condition, as the `AnimatedScene` asset should have a dependency on all subassets. This will fix it in the short term while I don't have a more "proper" solution. Perhaps I need to manually check the "recursive dependency load state" using the asset server?
1 parent 9e0a263 commit a6671d7

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

  • crates/bevy_animation_graph/src/core/animated_scene

crates/bevy_animation_graph/src/core/animated_scene/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub(crate) fn spawn_animated_scenes(
9090

9191
let processed_scene = if animscn.processed_scene.is_some() {
9292
animscn.processed_scene.as_ref().unwrap()
93-
} else {
93+
} else if is_scene_ready_to_process(animscn, &scenes, &skeletons, &skeleton_colliders) {
9494
let Some(scene) = scenes
9595
.get(&animscn.source)
9696
.and_then(|scn| scn.clone_with(&app_type_registry).ok())
@@ -111,6 +111,8 @@ pub(crate) fn spawn_animated_scenes(
111111

112112
animscn.processed_scene = Some(scenes.add(scene));
113113
animscn.processed_scene.as_ref().unwrap()
114+
} else {
115+
continue;
114116
};
115117

116118
commands
@@ -119,6 +121,22 @@ pub(crate) fn spawn_animated_scenes(
119121
}
120122
}
121123

124+
/// Checks whether the scene can be processed
125+
fn is_scene_ready_to_process(
126+
animscn: &AnimatedScene,
127+
scenes: &Assets<Scene>,
128+
skeletons: &Assets<Skeleton>,
129+
skeleton_colliders: &Assets<SkeletonColliders>,
130+
) -> bool {
131+
scenes.contains(&animscn.source)
132+
&& skeletons.contains(&animscn.skeleton)
133+
&& animscn.colliders.as_ref().is_none_or(|c| {
134+
skeleton_colliders
135+
.get(c)
136+
.is_some_and(|c| skeletons.contains(&c.skeleton))
137+
})
138+
}
139+
122140
/// This function finds the [`bevy::animation::AnimationPlayer`] and replaces it with our own.
123141
///
124142
/// It also applies retargeting if necessary.

0 commit comments

Comments
 (0)