How to fix animation not playing in Godot 4

I’m using Godot 4.x and I’m facing an issue where my animation is not playing when I try to trigger it.

I have set up an AnimationPlayer and created the animations correctly, but when I run the scene and press the input key, nothing happens.

What I expected:

The animation should start playing when I press the assigned key.

What actually happens:

Nothing plays, and there is no error in the output.

My setup:

  • Godot version: 4.x
  • Using AnimationPlayer node
  • Animation name is correct
  • Input action is already defined in Input Map

if Input.is_action_just_pressed(“attack”):
$AnimationPlayer.play(“attack”)

What I already tried:

  • Checked animation name spelling
  • Verified AnimationPlayer node path
  • Recreated animation
  • Checked Input Map settings

But still the animation does not play.

Can anyone help me figure out what I’m missing?

Can you share more of your code? Where do you call this if statement?

try using _input function and check if input is pressed - it should work as just pressed

I was just playing around with an input key command and nothing happened until I clicked on the window with the mouse. It’s like it wasn’t in focus or something. I am using linux right now so I don’t know if that had something to do with it.