The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

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

Godot version Godot 3.5
in Engine by (21 points)

1 Answer

+1 vote
Best answer

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":   
by (376 points)
selected by

Omg it worked! Thank u so much! :D

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.