Is there a way to restart or reset an AnimationPlayer animation that is non-looping?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By avencherus
:warning: Old Version Published before Godot 3 was released.

I have an issue where I’m trying to code an animation to play, but I don’t want it to be a looping animation. I want it to play from start to finish every time it’s called while it isn’t already playing.

But it doesn’t seem to restart from the beginning, and I can’t easily find any method for resetting or rewinding the time line of an animation.

Hmm, the regular play() function of AnimationPlayer always starts at the beginning for me.

rgrams | 2016-08-25 18:40

:bust_in_silhouette: Reply From: genete

Seek doesn’t work?

Ah, yes, missed that. I suppose it does, but it doesn’t stop the animation player. I’ve found though that stop() in script by default will reset the animation, so it does the same as seek(0).

Thanks for pointing me to that. X)

avencherus | 2016-08-21 15:15

:bust_in_silhouette: Reply From: AndruhaVuho

AnimationPlayer method play() restarts animation if it was stopped

$AnimationPlayer.stop()
$AnimationPlayer.play(anim)
:bust_in_silhouette: Reply From: delington

For my case to correctly reset the animationSprite I had to set the frame back to 0.

animation_sprite.frame = 0
animation_sprite.play()

https://www.reddit.com/r/godot/comments/o6kplj/comment/idh7ltt/?utm_source=share&utm_medium=web2x&context=3

AnimationPlayer, NOT animationSprite

jufry a. | 2023-05-09 03:53