Having problem with connect a signal from packedscene instance to the main scene

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

I’m learning Godot using Godot Engine Game development projects and I came across this code that bugs me. It’s from chapter 4 “Space Rocks”. I am instancing a scene called rock in the main scene using export (Packed scene). The rock scene has a code to explode when the player shoot it

I connected an exploded signal in the main scene

   func spawn_rock(size, pos=null, vel=null
            var r = Rock.instance()
             #Rocks is a child note of the main scene
             #I'm using Rocks node as a container for the rock scene
              r.connect("exploded", self, "on_Rock_exploded")

Then connected the function _on_Rock_exploded
The _on_Rock_exploded was suppose to explode the rock and split it into two but when I run it doesn’t happen. And then debugger showed this emit_signal: Error calling method from signal 'exploded': 'Node(Main.gd)::on_Rock_exploded': Method not found
I tried everything but it always show that error. I don’t know what to. Please Help
The code for the _on_Rock_exploded is below

  func _on_Rock_exploded(size, radius, pos, vel):
            if size <= 1: 
            for offset in [-1,1]:
                  var dir = (pos - $Player.position).normalized().tangent() * offset
                  var newpos = pos + dir * radius
                  var newvel = dir * vel.length() * 1.1
                  spawn_rock(size -1, newpos, newvel)
:bust_in_silhouette: Reply From: Zylann

Godot is telling you it cannot find 'Node(Main.gd)::on_Rock_exploded':, because:

r.connect("exploded", self, "on_Rock_exploded")

You missed a _ at the beginning of the function name.

Thank for the help.
The debugger issue was solved but the split into two rocks issue is still happening. There are no errors but when I run the game and shoot the rocks it just explodes instead of exploding and splitting into two

Kurizu78 | 2020-09-17 15:56

You may have to put a breakpoint in _on_Rock_exploded(size, radius, pos, vel) and see what are the argument values. Perhaps it’s receiving the wrong size?

Zylann | 2020-09-17 17:50

I checked func _on_Rock_exploded() function and all codes inside it and matched it with the codes on the book and found no mistake. I am suspecting that it has to do with animation_finished() signal
I have a animation_finished() signal connected in Rock scene’s script

func _on_AnimationPlayer_animation_finished(anim_name):

I think the problem is because of thequeue_free() but I am not sure.

Kurizu78 | 2020-09-25 10:43