How can I return an AnimationPlayer seek to the beginning without an error?

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

The following code is the code I’m trying to animate GUI.

func play_anim():
	$MyControl.visible = true  # The last frame is displayed...
	$MyControl/MyAnimationPlayer.play("MyAnim")

When this function is executed for the second time or later, the last frame can be seen.
When the animation finishes, the seek may be the last frame.
I am in trouble if I can not see the first frame.
So I tried the following.↓

func play_anim():
	$MyControl.visible = true
	$MyControl/MyAnimationPlayer.seek(0, true)  # red error
	$MyControl/MyAnimationPlayer.play("MyAnim")

This code does not stop but a red error appears.
error:

 Condition'!Playback.current.from'is true.

How can I return an AnimationPlayer seek to the beginning without an error?

Which version are you using? Godot 3.0.6 or 3.1 beta8?

Zylann | 2019-02-28 13:45

Thank you for your comment, Zylann.
I am sorry that there are incompleteness.
I am using “Godot Engine v3.1.beta5.official”.

Eclair | 2019-02-28 18:56

I tested your code in a simple project and I get the error only once. It happens because before the first call to play(), there is no current animation, so seek has nothing to seek through. Is that the case for you?

Zylann | 2019-02-28 20:09

I do not understand it well, but I think it is probably the case.
I tried the following code with reference to your comment.

func play_anim():
    $MyControl.visible = true
    $MyControl/MyAnimationPlayer.play("MyAnim")
    $MyControl/MyAnimationPlayer.seek(0, true)  # no error

By executing seek () after play (), no error occurred.

Thank you for testing the code and thinking together to solve the problem.
Your advice solved the problem.
Thank you so much, Zylann! XD

// ==========================================//
I also tried the following code, but it was not good.

$MyControl/MyAnimationPlayer.seek(0) # bad.

or

$MyControl/MyAnimationPlayer.seek(0, false) # bad.

After the second time, the last frame is displayed so it is not good.
// ==========================================//

Eclair | 2019-02-28 21:30

:bust_in_silhouette: Reply From: mrimvo

I’m using Godot 3.2 and this works for me to not get the error:

if current_animation!="":
    print(current_animation_position)
    seek(0)

The reason is obviously: when there was never an animation played, you can’t access its position or seek through it.

That may be obvious, but I didn’t know at first…
I think it would have been easier to understand if there were notes in “Documents» Godot API »Animation Player”.
Thank you for your answer, mrimvo.

Eclair | 2020-05-06 19:55

Oh I’m sorry I didn’t meant to be rude. Sorry for my poor choice of words, I rather meant to say “the reason seems to be”. I stumbled over the same problem and I think it’s great we have a place here to help each other out. :slight_smile:

mrimvo | 2020-05-06 20:40

Oh! Excuse me.
I am not complaining to you either.
I’m sorry that I’m not good at English and I can’t communicate well.

Your comments are useful and it’s a good study for me.
Many thanks for your comment !! XD

Eclair | 2020-05-07 08:54

Thanks a lot man. I kinda guessed what was the problem, but didn’t knew, how to solve it :’

Heiden | 2021-10-29 17:52

There was an animation I wanted to repeat.

At the end of the animation, it remained the last frame of the animation.

When I redisplayed and animated, I saw the end of the animation, not the beginning.

I used “seek ()” because I want to run the animation from the beginning every time.

Then an error occurred.

I used “seek ()” before “play ()”.

From the answer here, I interpreted it as follows.

Since “seek ()” is a function used for the animation being played, it had to be used after “play ()”.

I’m sorry if I said something strange, Heiden.

Eclair | 2021-10-29 19:54