From 93def2611b5c2d4d7e517d1cc8356b36f96328d1 Mon Sep 17 00:00:00 2001 From: Hannes Karppila <2204863+Dentosal@users.noreply.github.com> Date: Mon, 22 Jul 2024 22:17:46 +0300 Subject: [PATCH] Fix repeated animation transition bug (#14411) # Objective Fixes #13910 When a transition is over, the animation is stopped. There was a race condition; if an animation was started while it also had an active transition, the transition ending would then incorrectly stop the newly added animation. ## Solution When starting an animation, cancel any previous transition for the same animation. ## Testing The changes were tested manually, mainly by using the `animated_fox` example. I also tested with changes from https://github.com/bevyengine/bevy/pull/13909. I'd like to have an unit test for this as well, but it seems quite complex to do, as I'm not sure how I would detect an incorrectly paused animation. Reviewers can follow the instructions in #13910 to reproduce. Tested on macos 14.4 (M3 processor) Should be platform-independent, though. --- crates/bevy_animation/src/transition.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/bevy_animation/src/transition.rs b/crates/bevy_animation/src/transition.rs index f419f6e9c9..77e8fdfef5 100644 --- a/crates/bevy_animation/src/transition.rs +++ b/crates/bevy_animation/src/transition.rs @@ -92,7 +92,11 @@ impl AnimationTransitions { } } - self.main_animation = Some(new_animation); + // If already transitioning away from this animation, cancel the transition. + // Otherwise the transition ending would incorrectly stop the new animation. + self.transitions + .retain(|transition| transition.animation != new_animation); + player.start(new_animation) }