0 votes

Hello,

I have a scene which contains a sprite which contains an animationplayer.
While running I add several of those sprite-scenes to my current tree. (via add_child()) and start the animation of some of them.

In order to realize when the animation of the animationplayer is finished I listen to the "onanimation_finished" signal. This works well. The only problem is:

Since I have several animations I get several answers. Each for every instanciated scene where I started the animation.

Is there any way to find out if a finished animation is the final of all animations started?

thanks in advance,
grettyr

in Engine by (28 points)

1 Answer

0 votes
Best answer

This is possible by just counting the animations:

var animation_count = 0

Now you increment this number every time you start an animation:

animation_count += 1

In your function connected to the onanimation_finished signal, you decrement this number and check if this was the last animation:

animation_count -= 1
if animation_count == 0:
    print("This was the last animation")
by (698 points)
selected by

Thanks for your answer. I was hoping for a "more elegant" solution but this will do.

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.