Godot: AnimationPlayer: Add animation name to "finished" signal

Created on 6 Jan 2017  路  11Comments  路  Source: godotengine/godot

Operating system or device - Godot version:
Godot c798ff1

Issue description (what happened, and what was expected):

The finished signal needs the current animation name as argument like animation_started(String name).

Now:

func _on_AnimationPlayer_finished():
    if get_node("path/to/AnimationPlayer").get_current_animation() == 'explode':
        emit_signal('explode')

With animation name:

func _on_AnimationPlayer_finished(current_animation):
    if current_animation == 'explode':
        emit_signal('explode')
enhancement core

Most helpful comment

An additional signal would probably be better, because finished indicates that the animation player finished playing any animation.

signal animation_finished(String name) which gets emitted every time an animation finished.

And the documentation for finished is also wrong, it says "Notifies when an animation finished playing", but as said it only notifies if the animation player finished a non loop animation and no other animation is queued.

And if we want to break compatibility we could set the current_animation to "", when finished gets emitted, shouldn't have any use with the new signal animation_finished and would allow to use:

if anim_player.get_current_animation() != "jump":
    anim_player.play("jump")

instead of:

if anim_player.get_current_animation() != "jump" AND anim_player.is_playing():
    anim_player.play("jump")

All 11 comments

I think this was done a few months ago, then reverted as it broke compatibility. @reduz Maybe something to reconsider for 3.0?

An additional signal would probably be better, because finished indicates that the animation player finished playing any animation.

signal animation_finished(String name) which gets emitted every time an animation finished.

And the documentation for finished is also wrong, it says "Notifies when an animation finished playing", but as said it only notifies if the animation player finished a non loop animation and no other animation is queued.

And if we want to break compatibility we could set the current_animation to "", when finished gets emitted, shouldn't have any use with the new signal animation_finished and would allow to use:

if anim_player.get_current_animation() != "jump":
    anim_player.play("jump")

instead of:

if anim_player.get_current_animation() != "jump" AND anim_player.is_playing():
    anim_player.play("jump")

@akien-mga Oh, I see! I think implementing it in 3.0 is a good one.

I'm here just because this issue was referenced from my other one :).

@bebae why would you have multiple finished signals? It doesn't make any sense. You can only play/finish one animation at a time.

@razvanc-r Currently as it is finished gets emitted when the animation player finish an animation and no other animation is queued. So currently it is a signal that indicates that the AnimationPlayer is finished and has nothing to do with a specific animation. At least that is how it behaves, the documentation is different.

But if we want a signal that also returns the animation name it should be named signal animation_finished(String name), because all other signals which return the animation are named animation...

I don't really care about the finishedsignal but it probably could still be useful if you have some oneshots with randomized animations and you only care about when the animation player is finished, but this could also be done with animation_finished i guess.

edit:
Just saw that you removed the "animation_" part from changed and started. So your suggestion should be fine. Shorter names are better. The main idea behind two finished signals was that the others had animation_ as prefix to keep it consistent. And just to keep finished at it is, because its already there.

The method in animation_finished signal is called with 1 argument but it doesn't appear to contain the name of the finished animation, theAnimPlayer.get_current_animation() is also empty at this point. The animation does play and the method is called. This is in the current tip of godot 3.

Ah, this still happens! anim_name is empty for animation_finished signals. One way around it is to manually connect the animation_finished signal and pass anim name as a variable:
subtitleAnimPlayer.connect("animation_finished", self, "_on_subtitleAnimPlayer_finish", ["fade"])

Try using assigned_animation instead of current_animation. In 3.0, current_animation becomes "" when the animation player is no longer playing.

This issue is fixed in 3.0, the animation_finished signal comes with the animation name as argument, and it works fine in this example:
anim_finished.zip

If you found a situation where it doesn't work as intended, please open a new issue with detailed steps to reproduce and an example project.

Hello, this still seems to not work properly... I connected an animation_finished to a function, but this function is never called.. when I print current_animation, I get nothing...

@jordanlis Please open a new issue with a minimal reproduction project attached.

That said, keep in mind you can't access current_animation in animation_finished():

In 3.0, current_animation becomes "" when the animation player is no longer playing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Spooner picture Spooner  路  3Comments

bojidar-bg picture bojidar-bg  路  3Comments

ducdetronquito picture ducdetronquito  路  3Comments

SleepProgger picture SleepProgger  路  3Comments

testman42 picture testman42  路  3Comments