Animation won't play when changing it. It just stays at the first frame

Godot Version



I am using sprite_2d.animation = “animation” (it is an animated sprite), but it only plays the first frame. I do have one animation that only plays one frame, but that shouldn’t be the issue.

Could you post a screenshot of the sprite frames panel? And/or more of your script?


extends CharacterBody2D
@onready var sprite_2d = $Sprite2D

const SPEED = 300.0
const JUMP_VELOCITY = -400.0
var isLeft = false
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")

func _physics_process(delta):
	if (velocity.x > 1 || velocity.x < -1):
		sprite_2d.animation = "running"
		sprite_2d.animation = "idle"
	# Add the gravity.
	if not is_on_floor():
		velocity.y += gravity * delta
		sprite_2d.animation = "jumping"
	# Handle Jump.
	if Input.is_action_just_pressed("ui_accept") and is_on_floor():
		velocity.y = JUMP_VELOCITY

	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	var direction = Input.get_axis("ui_left", "ui_right")
	if direction:
		velocity.x = direction * SPEED
		velocity.x = move_toward(velocity.x, 0, SPEED)

	if velocity.x != 0: 
		isLeft = velocity.x < 0
	sprite_2d.flip_h = isLeft

I used the beginner tutorial from Coco Code.

Sorry it only lets me send one at a time.

Try changing to"animation") maybe the one-frame animation thinks it’s done animating?

I have tried that. It just crashes.

crashes? no error or stack trace?

Oh clearly I did sum wrong cuz it works just fine now! Thank you so much tho!