0 votes

First of all I'm new to godot and trying to follow some tutorials to produce a very basic game, the current tutorial is teaching to make a game in which the player dodges enemies. However when a collision is detected nothing happens as the method cannot be found even though it all seems to be spelled correctly, giving the error:

emitsignal: Error calling method from signal 'bodyentered': 'Area2D(Player.cs)::PlayerHit': Method not found..

The connection is made in the ready procedure for the player.

Connect("body_entered", this, nameof(PlayerHit));

and this is the routine I'm trying to get it to call:

public void PlayerHit()
{
    Hide(); // Player disappears after being hit.
    EmitSignal("Hit");
    GetNode<CollisionShape2D>("CollisionShape2D").SetDeferred("disabled", true);
}

Any help would be greatly appreciated.

asked May 22 in Engine by Polyaxial (15 points)

1 Answer

+1 vote
Best answer

body_entered expects the function to receive a Node, you need to change the function to this:

public void PlayerHit(Node body) { ... }
answered May 23 by davidoc (746 points)
selected May 23 by Polyaxial

Thanks so much i was really stuck and it was as simple as that :)

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.