Hello all,
I am pretty new to godot and have been trying to code my first game. However, I have run into a problem with my enemy scene. The AnimatedSprite has 2 animations: "walk" and "idle". I have created functions for the enemy to follow the player when within a certain range of the player, and within these functions added a command to change the animation state to the respective animation. However, when I first start the scene, the enemy always defaults to the walk animation. If the play trips it's follow mechanic, and then goes outside of its range, it goes back to the idle animation and everything works as it should. I have tried several solutions and I cannot get it to work. If anyone knows how to fix this, please let me know!

I have attached my code and node tree for help.

extends KinematicBody2D

export (int) var health := 10

onready var _animated_sprite = $AnimatedSprite

var speed = 50
var motion = Vector2.ZERO
var player = null


func _physics_process(delta):
	motion = Vector2.ZERO
	if player:
		motion = position.direction_to(player.position) * speed
	motion = move_and_slide(motion)

func handle_hit(damage: int):
	health -= damage
	if health <= 0:
		queue_free()

func _on_Area2D_body_entered(body):
	player = body
	_animated_sprite.play("walk")

func _on_Area2D_body_exited(body):
	player = null
	_animated_sprite.play("idle")

func _on_Hitbox_body_entered(body):
	if "Sword" in body.name:
		Global.score += 1
		queue_free()

try in the function ready to put with which animacon you want it to start

    el_malo I already tried that and it didn't work. I forgot about the issue and worked on some other aspects of the game and the animation issue is now fixed for some reason lol.

      You may have had a default animation selected when you made the sprite. Sometimes when you make new animations, the sprite likes to default to the last one you used. My guess is that might be what happened.

      The other thing I noticed in Godot is if you have an object in an area that it "listening" for it when you say, launch a scene test, even when you move it, Godot likes to say it was there because "technically" it was there at the ready before it moved to its proper location. Of course you can code around that, but be aware.