0 votes

I have a simple enemy script where the enemy follows the player and the player can damage the enemy. I was recently trying to add a death effect with animation to the enemy. I did that and everything works fine except that I get an error-message like every half-second.
The error message is as following:

emitsignal: Error calling method from signal 'animationfinished': 'KinematicBody2D(Enemy.gd)::onAnimatedSpriteanimationfinished': Method not found..

This is the enemy script:

extends KinematicBody2D

const GRAVITY = 10
const UP = Vector2(0, -1)

var motion = Vector2()
var is_dead = false

onready var animsprite = $AnimatedSprite
onready var player = get_parent().get_node("Player")
onready var stats = $Stats

func _physics_process(delta):
motion.x = clamp(motion.x, -stats.speed, stats.speed)

if is_dead == false:
    if player.position.x > position.x:
        motion.x = stats.acceleration
        animsprite.scale.x = 1
    elif player.position.x < position.x:
        motion.x = -stats.acceleration
        animsprite.scale.x = -1
        motion.x = lerp(motion.x, 0,0.2)

motion.y += GRAVITY

motion = move_and_slide(motion, UP)

func _on_Hurtbox_area_entered(area):
stats.health -= area.damage

func _on_Stats_no_health():
motion.x = 0
is_dead = true
yield(animsprite, "animation_finished")

Im sure the problem has something to do with the "onStatsnohealth():" function and the "if is_dead == false:" statement because I didn't get the error message before I added that "if" statement, but then the idle animation would play instead of the death animation when the enemy dies.

I feel like I am missing something simple. Any help is appreciated!

Godot version 3.2.3 stable
in Engine by (38 points)

1 Answer

0 votes
Best answer

Looks to me like you changed the name of a function connected by a signal(animation_finished) from the AnimationPlayer and now Godot's going bananas looking for it.

Simply change the node signal connection to the appropriate function or remove the connection

by (4,604 points)
selected by

Wow that was it. Seems like I hade forgotten to disconnect the signal from the animatedsprite to the enemy script. Thank you very much!

Not a problem.
When i first started had a lot of trouble remembering what signals were connected to where and it became a nightmare to manage the more my project grew.

That's why i do all my signal connections through code now. You live you learn

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 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 webmaster@godotengine.org with your username.