diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index 8d7cfa9925557..924652c4a9dd4 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -115,7 +115,7 @@ impl Default for AnimationPlayer { impl AnimationPlayer { /// Start playing an animation, resetting state of the player - pub fn play(&mut self, handle: Handle) -> &mut Self { + pub fn start(&mut self, handle: Handle) -> &mut Self { *self = Self { animation_clip: handle, ..Default::default() @@ -123,6 +123,14 @@ impl AnimationPlayer { self } + /// Like `start`, but does nothing if the requested animation is already playing. + pub fn play(&mut self, handle: Handle) -> &mut Self { + if self.animation_clip != handle || self.is_paused() { + self.play(handle); + } + self + } + /// Set the animation to repeat pub fn repeat(&mut self) -> &mut Self { self.repeat = true;