How to use the animation_finished signal

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

I want to make a few animations behind other animations when they finished but with out a Timer. What is wrong ( if animation_finished(“name”): print(“test”)) ?

Did you properly set up the signal connections for the animations? Do any of the animations loop?

Ertain | 2020-12-20 19:49

Hey there!
This is just not how signals work in Godot, you have to connect them to a script through the “Node” tab that is right next to the Inspector. When you do so, a new function will be created on your script. It should look something like:


I’m not sure if this is how the name looks like by default… Anyways, this function (that may have any name you wish as long as you connect it from the Node tab) will be called every time an animation finishes.

So, taking your code as an example… It should look like this, if correctly used the function.

	if anim_name == "name":

Hope I helped you!
Basicly the function is automatically called once the even triggers.

If you want to learn more about signals, check this page on the docs.

NikiDev | 2020-12-20 22:28

Ok, thanks it works.

Bot7 | 2020-12-23 13:24

:bust_in_silhouette: Reply From: Lopy

For a signal named animation_finished inside an object named anim.

  • Objects tell anim that they are interested to know when animation_finished happens.
    anim.connect("animation_finished", interested_object, "function_to_call")

  • Anim eventually notifies everyone.
    emit_signal("animation_finished", animation_name)
    (default nodes emit their signals automatically)

  • This causes a bunch of interested_object.function_to_call(animation_name) to be executed.

In your case, you want to make a function, say _on_finished(name: String),
and connect it to your AnimationPlayers animation_finished, inside a _ready().
func _ready():
. anim.connect("animation_finished", self, "_on_finished")
func _on_finished(name: String):
. print("Finished ", name)

1 Like

is there a way so that when an animation is done then it will load a scene?

Thank you for helping me, I just can’t manage to place the order

if anim_name == "name":

You can also use this command $AnimationPlayer.callable("animation_started",self,"OnAnimationStarted")