Search code examples
c#signals-slotsgodot4

Signal Method not Found even Though Method is Referenced in Godot C#


I have been following this tutorial on creating a Character Movement System where I ran into a problem related to signals. I was trying to have Spikes Node2D with an Area2D child send a signal when a body entered its CollisionShape2D. I was successfully able to connect the signal to the Spikes Node2D and I Ctrl + C the receiver method then added it to Spike Script.

private void _on_area_2d_body_entered()
{
    GD.Print("Body has entered");
}

On VS, it says that there is 1 reference to the receiver method, though I cant seem to access the code where it is called. That being said, whenever my Player CharacterBody2D passes through the Spikes' Sprite2D, which is perfectly aligned with the CollisionShape2D, I get the following debug error:

emit_signalp: Error calling from signal 'body_entered' to callable:
'Node2D(SpikeTrap.cs)::_on_area_2d_body_entered': Method not found.

I followed the tutorial, and the guy added object body as parameters in the method. When I did the same, I got no references to my method. I have no clue what is going wrong here.

I watched that part in the video multiple times, and I searched through google and the Godot documentation to no avail.


Solution

  • In the tutorial, the guy passes in a parameter object body, which does not work anymore. You have to pass in specific nodes, like Node2D or CharacterBody2D. Like so:

    private void _on_area_2d_body_entered(CharacterBody2D body)
        {
            GD.Print("Body: " + body + " has entered");
        }