0 votes

Hi all,

I'm pretty new to Godot and I'm a bit lost with this error.
I use gdScript.

I have created a class "Enemy" which holds basic variables, like "life", "speed", etc., which is a KinematicBody2D.

Then I have a "Slime", which extends Enemy and is attached to a KinematicBody2D Scene. A child scene is an Area2D, called "Hurtbox".
Now I want to implement the signal "area_entered" of the Hurtbox to signal to a method in Slime. This method is not declared in Enemy.

In Slime I have connected the signal in _ready:

# Slime.gd
extends Enemy

var hurtbox

func _ready():
 hurtbox = $Hurtbox
 hurtbox.connect("area_entered", self, "_on_Hurtbox_area_entered")

func _on_Hurtbox_area_entered(bullet : Area2D):
 print("in _on_Hurtbox_area_entered")

Well, the function works. I have removed a bit more of the logic, but the "hit" signal is emitted and the enemy looses life and dies correct.
But every time the function is called, I get the following error in the Debugger:

E 0:00:07.292   emit_signal: Error calling method from signal 'area_entered': 'Area2D::_on_Hurtbox_area_entered': Method not found..
  <C++ Source>  core/object.cpp:1242 @ emit_signal()

I tried connecting the signal in the editor, but it has the same effect.

I also tried declaring the function in the parent class Enemy. But that also changes nothing.

Thanks for your help.

Godot version 3.5
in Engine by (12 points)

didn't You connect something else to that signal elsewhere ?


I don't understand what the parent has to do with it. I don't reference the parent, like in the other thread.

didn't You connect something else to that signal elsewhere ?

Well, every slime instance does this, with multiple on screen on the same time. But not somewhere else in the script if you mean that.

Also, the player got a hurtbox scene that gets connected to a method in the player script.

In the future every enemy is supposed to get that. But every instance of hurtbox is always only connected to one instance of enemy or player method.

I am very new to this, so please correct me if I go about this wrong.
My idea behind this was to create a simple scene that I could reuse for everything that can be hit.

The thing is your signal is working correctly, but an error is thrown anyways.
It makes me suspect, that error comes from only one instance, while everywhere else it work perfectly fine.
I assume it comes from your player. You must have connected it to the same method, but made a typo. Can You show players code with connections ?

I tried it and removed the Hurtbox from the player entirely, but it happened anyway. So it was only added to the Slime scene and no manual connections in the editor. And the error only occured when an enemy got hit, so only when the signal was actually fired.

So the last config was no signal connection through editor, only through code in the instance it was added to in _ready().

But what I do now to make it not throw the error is: I removed the predefined Hurtbox scene and just build a new one in every enemy and player scene by manually adding the nodes. It works that way without any errors.

Please log in or register to answer this question.

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.