Trouble connecting Signals from GDScript to C#

Godot Version

4.3 Stable

Question

I am having trouble creating a C# version of a GDScript project.
Using GDScript, I created a Deadzone that exits the game in case the Player reaches out of bounds.

# Called when the player touches the deadzone
func _on_hitbox_area_entered(area: Area2D) -> void:
		get_tree().quit()

This is my Node Tree setup for the Player.

Screenshot from 2024-09-04 14-18-04

I added a Scene Group for deadzone
I added a Scene Group to Hitbox titled player

I tried refering to the C# API differences to GDScript but I could not understand any of the comparisons.

Could someone please help me with this?

here are some c# signal examples to help you get started.

example #1
public partial class MyTimer:Timer {
	void DoTimeout() {
		GD.Print("normal function");
		Disconnect(Timer.SignalName.Timeout, Callable.From(DoTimeout));
	}
	public override void _Ready() {
		Action v_variable_timeout_function = () => {
			GD.Print("function stored as a variable");
		};
		Start(2);
		//  #1 - using method
		Connect(Timer.SignalName.Timeout, Callable.From(DoTimeout));

		// #2 - using action variable
		Connect(Timer.SignalName.Timeout, Callable.From(v_variable_timeout_function));

		// #3 - anonymous function
		Connect(Timer.SignalName.Timeout, Callable.From(() => {
			GD.Print("anonymous function");
		}));
	}
}
example #2 - custom signal
public partial class MySignal:Node {

	//////////////////////////////////////////////////////////////
	// [Signal] is how we create a signal for Godot in c#   //////
	//////////////////////////////////////////////////////////////

	// please note: delegate must end in --> EventHandler <--

	[Signal]
	public delegate void MyHelloWorldEventHandler(); // SignalName.MyHelloWorld created!

	[Signal]
	public delegate void MyTestEventHandler(); // SignalName.MyTest created!

	///////////////////////////
	// callable functions /////
	///////////////////////////

	// no arguments
	// Callable.From(DoTest)
	void DoTest() {
		GD.Print("############### This is a test ##################");
	}


	// string argument
	// Callable.From<string>(DoHelloWorld)
	void DoHelloWorld(string a_message) { 
		GD.Print(a_message);
	}




	public override void _Ready() {

		//////////////////////////
		// connect signals  //////
		//////////////////////////

		Connect(SignalName.MyTest, Callable.From(DoTest)); // no arguments
		Connect(SignalName.MyHelloWorld, Callable.From<string>(DoHelloWorld)); // string argument

		////////////////////////
		// emit signals ////////
		////////////////////////

		EmitSignal(SignalName.MyHelloWorld, "This is a message from the future");
		EmitSignal(SignalName.MyTest);
	}
}

you trying connect signal, create signal?

C# will be

//  Called when the player touches the deadzone
public void OnHitboxAreaEnter(Area2D area)
{
 GetTree().Quit();
}

pick and connect in signal inspector

2 Likes