error connecting signal to method - method not found

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

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")
 emit_signal("hit")
 [...]

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.

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

Inces | 2022-09-19 14:43

look
How do I solve "error calling method from signal" error - Archive - Godot Forum

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

Linkk | 2022-09-19 18:41

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.

Linkk | 2022-09-19 18:49

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 ?

Inces | 2022-09-19 19:35

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.

Linkk | 2022-09-20 21:21

:bust_in_silhouette: Reply From: tmgodot12

In my case I had this error removed by doing these:

  1. signal “start_game” ->changed to “startgame”
  2. HUD.scn - the signal “startgame” is defined and emmited internaly inside this scene(script)
  3. Main node
    -child instanced HUD.tscn - “startgame” signal is here connected to Main.gd method new_game()
    Maybe something here will help.