Stop current animation and re-play immediately?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rico345100

When the player hit something, I’m playing hit animation from animation_player. However when player hit something while hit animation is playing, it just ignored and play previous hit animation.

I need to stop the animation, but couldn’t find any related information. How do I stop the animation and play again immediately?

:bust_in_silhouette: Reply From: Daniel Tebbutt

If you call .stop(true) on the animation player, it will reset to the start of the animation. So when you want to play the hit animation, you can call .stop(true) and then immediately call .play() to play from the start.

The true you pass to stop is telling it to reset the animation to the beginning. If you call stop without passing that, it will just pause and resume next time you call play().