From 20264d0810be5f4e74dd1fdf5d0492e1337eccc1 Mon Sep 17 00:00:00 2001 From: Lixou <82600264+DasLixou@users.noreply.github.com> Date: Wed, 31 Jul 2024 16:07:53 +0200 Subject: [PATCH] Make `AnimationPlayer::start` and `::play` work accordingly to documentation (#14546) # Objective While scrolling through the animation crate, I was confused by the docs and code for the two methods. One does nothing for resetting an animation, the other just resets the weights for whatever reason. ## Solution Made the functions work accordingly to their documentation. `start` now replays the animation. And `play` doesn't reset the weight anymore. I have no clue why it should. `play` is there to don't do anything to an already existing animation. ## Testing I tested the current 0.14 code with bevy playground in the Animated Fox exampled and changed it such that on pressing space, either `play` or `start` would be called. Neither changed anything. I then inlined the function for start there and it restarted the animation, so it should work. --- ## Migration Guide `AnimationPlayer::start` now correspondingly to its docs restarts a running animation. `AnimationPlayer::play` doesn't reset the weight anymore. --- crates/bevy_animation/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index 48fe2e1192..1437e6ce28 100755 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -564,14 +564,14 @@ thread_local! { impl AnimationPlayer { /// Start playing an animation, restarting it if necessary. pub fn start(&mut self, animation: AnimationNodeIndex) -> &mut ActiveAnimation { - self.active_animations.entry(animation).or_default() + let playing_animation = self.active_animations.entry(animation).or_default(); + playing_animation.replay(); + playing_animation } /// Start playing an animation, unless the requested animation is already playing. pub fn play(&mut self, animation: AnimationNodeIndex) -> &mut ActiveAnimation { - let playing_animation = self.active_animations.entry(animation).or_default(); - playing_animation.weight = 1.0; - playing_animation + self.active_animations.entry(animation).or_default() } /// Stops playing the given animation, removing it from the list of playing