There's something wrong with this? Stack overflow (Stack Size: 1024)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By R4mp3t

##Hello, I’m having a problem that says “Stack overflow (Stack Size: 1024)” when I want to queue_free( ) an enemy when dies after an animation

extends KinematicBody

onready var Anim_play = $AnimationPlayer

var health = 100

func _ready():
	pass

func _process(_delta):
	if health <= 0:
		Anim_play.play("EnemyDeath")

func _on_AnimationPlayer_animation_finished(_anim_name):
	if _on_AnimationPlayer_animation_finished("EnemyDeath"):
		queue_free()

someone pls help

:bust_in_silhouette: Reply From: LeslieS

Your _on_AnimationPlayer_animation_finished() function is in an endless loop as you are calling it from within itself.
This line calls the function and thus you get an endless loop:

if _on_AnimationPlayer_animation_finished("EnemyDeath"):   

Just guessing by the code you are showing you should change it to:

if _anim_name == "EnemyDeath":   

Omg it worked! Thank u so much! :smiley:

R4mp3t | 2022-12-28 03:59