How do I check if a particular animation in an AnimationPlayer is playing or not?

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

I know I can use _on_TextBox_animation_finished but I’m looking for an active way to check it anywhere e.g. a var that’s true or false. Not sure what I could use. Basically I have a textbox that “slides” open when you talk to an NPC, but if you spam the “talk” button that brings it up, it interrupts this animation (I have multiple animations in this one player). So I’m trying to disable that neatly to make sure the input only works when the box has finished animating. Thanks.

:bust_in_silhouette: Reply From: Socrates

I think you can do:

if Animation.current_animation == "name of animation"

Thanks, tried that but it doesn’t seem to work. My problems are solved now if I just split up all my animations into a different player node for each one… A bit wasteful, but it’ll have to do for now.

jobax | 2018-03-30 08:24

:bust_in_silhouette: Reply From: jobax

My problems are solved now if I just split up all my animations into a different player node for each one… A bit wasteful, but it’ll have to do for now. No idea how to do this without a signal, still would appreciate any help there.

:bust_in_silhouette: Reply From: PhilipCz

For anyone still wondering. You can use $Sprite.animation to get the animation. Then use an if statement to check if that’s the animation that you need.

:bust_in_silhouette: Reply From: 333halfevil5

I know this is an old question but it’s something I just had an issue with and couldn’t directly find an answer for so I thought I would add what worked for me specifically.

You can use this code to check what animation is currently playing:

$AnimationPlayer.get_current_animation()

So for my example I use it as a check because I want my attack animation to play over anything else so before each animation I have this line:

if $AnimationPlayer.get_current_animation() != “Attack”:

then I would have the code to play whatever animation should be playing without the attack.