+2 votes

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?

in Engine by (40 points)

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

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

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?

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.
// ==========================================//

1 Answer

+1 vote
Best answer

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.

by (54 points)
selected by

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.

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. :)

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

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

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.