Invalid call. Nonexistent function 'play' in base 'Nil'. Game crashes

It doesn’t work, it suddenly stopped working. I tried disabling the animations and it worked, but I don’t know the problem.

extends CharacterBody2D

#variables
var _velocidad: float = 150.0
var _velocidad_salto: float @export -350.0
@export var animacion: Node

func _physics_process(delta):

#Idle
animacion.play("Idle")

#gravedad
velocity += get_gravity() * delta

#salto
if Input.is_action_just_pressed("ui_up") and is_on_floor():
	velocity.y = _velocidad_salto


#movimiento lateral
if Input.is_action_pressed("ui_right"):
	velocity.x = _velocidad
elif Input.is_action_pressed("ui_left"):
	velocity.x = -_velocidad
else:
	velocity.x = 0
move_and_slide()

#animaciones
if !is_on_floor():
	animacion.play("Jump")
elif velocity.x != 0:
	animacion.play("Run")
else:
	animacion.play("Idle")

is animacion supposed to be a AnimationPlayer, not a Node?
do you have an AnimationPlayer?

Check the value of the animacion property in the inspector of your CharacterBody2D node in the scene tree.

Is your AnimationPlayernode still assigned to it?

There are safer ways to address your AnimationPlayer node:

Using Ctrl-Z while editing your scene may just have unassigned animacion. Directly addressing a unique node %AnimationPlayer is safer that way.

Did you move any of the nodes around in the sceene tree? Or has the animation node been deleted or removed from the @export in the inspector?

You can use Node for AnimationPlayer and any other nodes that inherit from it (i.e. all nodes). Same for Object and any other things, as long as whatever you type inherits from that type it will not trigger any errors, to my knowledge.

Does this compile? What happened here? Copy/paste problem?

yeah my fault, was used to seeing statically typed variables..

Yes, but typing more narrowly in this case would have been helpful for autocomplete and quick navigation to useful documentation.

Also, the inspector will take the type hint as well and only offer AnimationPlayer nodes in the scene to assign.

I use an animated sprite

It finally doesn’t crash anymore, thank you everyone

copy paste problem, they are two separate lines

How did you solve it?