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")
Yes_MP
July 14, 2026, 9:14pm
2
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 get_node() to reference nodes from a script can sometimes be fragile. If you move a button in a UI scene from one panel to another, the button's node path changes, and if a script uses get_node() with a hard-coded node path, the script will not...
Using Ctrl-Z while editing your scene may just have unassigned animacion. Directly addressing a unique node %AnimationPlayer is safer that way.
baba
July 14, 2026, 9:30pm
4
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?
baba
July 14, 2026, 9:32pm
5
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?
Yes_MP
July 14, 2026, 9:37pm
7
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.
It finally doesn’t crash anymore, thank you everyone
copy paste problem, they are two separate lines