How to connect signal from C# to GDScript

Godot Version

4.2

I have declared a signal in c# using the following:

[Signal]
	public delegate void abcEventHandler(Boolean connect);

The i am later on emitting the singal using

EmitSignal("abcEventHandler", true );

How can i react on this signal in GDScript?

i am trying to do

connect("abc", someUpdateFunction)

However i get the following error:
In Object of type 'Node3D': Attempt to connect nonexistent signal 'abc' to callable 'Node3D(someScript.gd):: someUpdateFunction'

I have tried abcEventHandler as well

The signal name is abcEventHandler isn’t it? Shouldn’t you be connecting to it instead of “abc”?

EDIT: I didn’t see that you tried that as well.

Have you tried connecting like so - connect(c_sharp_node.abcEventHandler, someUpdateFunction)

you have reference to object class sending signal?

func _ready():
	var MyNode = get_node("..")

Signal will be called from parent ".."

	if MyNode != null and MyNode.has_signal("MySignal"):
		MyNode.MySignal.connect(_print_me)

I checked if signal exist and connect method _print_me() to signal

func  _print_me():
	print("IsPrinted")

Parent C Sharp script

	public delegate void MySignalEventHandler();
	
    public override void _PhysicsProcess(double delta)
	{
		var error = EmitSignal(SignalName.MySignal);
	}

This should be correct way to connect signal from a node for godot 4

1 Like

Ok maybe i have a weird setup.

I have a node main.gd

This creates a new instance of the object MyCSharpScript.cs

MycSharpScript.cs is NOT a node (previously was, changed it). it does not extend the node class since this is isnt needed for me.

In main.gd i do the following:

var object
var my_csharp_script = load("res://scripts/MycSharpScript.cs")

func _ready():
	var MyNode = get_node("..")
	object = my_csharp_script.new()
	if MyNode != null and MyNode.has_signal("abc"): //tried abcEventHandler
		MyNode.abc.connect(someUpdateFunction)
	else:
		print("No such signal")
	object.begin("arg1")

In the logs i see “No Such Signal”

Q: Should i make it node?

Q: Can a non-node class emit a signal?

A script needs to extend at least from Object to be able to use Godot’s signal system. You can try using Object.get_signal_list() to get a list of signals from that object and see how it’s called.

3 Likes

try rename function to

_some_update_function

you sure parent sending signal?

I wasent able to get this working and decided to make my main scene in c# instead of gdscript.