AnimationPlayer.play("animation_name") returns "Animation not found: 'animation_name'" error

Godot Version

v4.2.stable.official [46dc27791]

Context

New to Godot so not sure if I’m doing something wrong or if this is a bug that should be logged on GH.

Following a 3.5 tutorial for a 3D project (using 4.2) everything has gone well until trying to do a simple attack animation on the player’s sword.

Setup

Here is the relevant code causing the error

extends CharacterBody3D
class_name Player

@onready var sword_anim: AnimationPlayer = $WeaponHolder/Sword/AnimationPlayer

var attack_rate: float = 0.3
var last_attack_time: int = 0

func _process(delta: float) -> void:
    if Input.is_action_just_pressed("attack"): 
        try_attack()

func try_attack() -> void:
    if Time.get_ticks_msec() - last_attack_time < attack_rate * 1000:
        return

    last_attack_time = Time.get_ticks_msec()
    sword_anim.stop()
    sword_anim.play("attack") # Line throwing error

Pretty straightforward overall.

Here is the information from the nodes/scene and such:

Question

Am I doing something wrong or missing a step that wasn’t needed in 3.5 somewhere? Feels like I’m doing it all right.

What I’ve tried with no success

  1. Renaming the animation (“attack2”, etc.)
  2. Deleting the animation entirely and recreating it
  3. Saving the animation as “attack.res” and importing that
  4. Deleting the AnimationPlayer node entirely and recreating it all
  5. Closing the project/Godot and reopening it (and hoping)
  6. Tried next day after computer reboot

What I find odd is that I can toggle the animation in the Animation Editor to Autoplay on Load and Loop and it WILL autoplay and loop. But as soon as I call the play() method manually on the AnimationPlayer it fails.

It looks like the path to the node should be:

@onready var sword_anim: AnimationPlayer = $WeaponHolder/AnimationPlayer
2 Likes

Well, I fell like a complete idiot.

That did it. Must have had it as a child when I created the variable or something and corrected the node later.

Glad that was a simple thing though.

Thank you!

EDIT:
I think what threw me off was that it seemed to still call .play on whatever object it found so I assumed it had been finding the correct object the whole time.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.