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
- Renaming the animation (“attack2”, etc.)
- Deleting the animation entirely and recreating it
- Saving the animation as “attack.res” and importing that
- Deleting the AnimationPlayer node entirely and recreating it all
- Closing the project/Godot and reopening it (and hoping)
- 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.