Skip to content

Commit

Permalink
fix repeated animation transition bug (14411)
Browse files Browse the repository at this point in the history
  • Loading branch information
robtfm committed Aug 15, 2024
1 parent ad4024e commit 2dd2880
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions crates/bevy_animation/src/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ impl Clone for AnimationTransitions {
#[derive(Debug, Clone, Copy, Reflect)]
pub struct AnimationTransition {
/// The current weight. Starts at 1.0 and goes to 0.0 during the fade-out.
current_weight: f32,
pub current_weight: f32,
/// How much to decrease `current_weight` per second
weight_decline_per_sec: f32,
pub weight_decline_per_sec: f32,
/// The animation that is being faded out
animation: AnimationNodeIndex,
pub animation: AnimationNodeIndex,
}

impl AnimationTransitions {
Expand Down Expand Up @@ -92,14 +92,23 @@ 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)
}

/// Obtain the currently playing main animation.
pub fn get_main_animation(&self) -> Option<AnimationNodeIndex> {
self.main_animation
}

/// Iterator over animations currently being transitioned out
pub fn get_transitions(&self) -> impl Iterator<Item=&AnimationTransition> {
self.transitions.iter()
}
}

/// A system that alters the weight of currently-playing transitions based on
Expand Down

0 comments on commit 2dd2880

Please sign in to comment.