Signals in c# (connect)

Godot Version

4.2

Question

Hi there, I read the documentation but, really, can’t figure it out how it works in C#…

in gdscript I do:
from script in A, I create an instance of B scene
Access the signal in B with: BInstance.connect(“SignalOnB”, functionInA)

how I do that in C#?
in script B I have: [Signal] public delegate void MyHelloEventHandler();
from script in A, I create an instance of B scene
How can I connect now the B signal to a function in A?

Thanks in advance

Here’s the documentation about C# signals C# signals — Godot Engine (stable) documentation in English

Hi Thanks for your reply, as I said I already read the documentation and still don’t understand how this works, please let me see what I don’t get…

If I have this:

public partial class keko : Node2D
{
[Signal]
public delegate void HelloEventHandler();

public override void _Ready()
{
    EmitSignal(SignalName.Hello);
}

}

why I can`t do this in a different script…

public partial class main : Control
{
public override void _Ready()
{
Button myButton=GetNode(“Button”);
myButton.Pressed+=OnButtonPressed;

    Node2D myKeko=GetNode<Node2D>("Keko"); 
    myKeko.Hello+=OnHello;   //Error    
}

private void OnButtonPressed(){
    Print("Button");
}

private void OnHello(){
    Print("Hello!!");
}

}

Thanks in advance

Node2D does not have a Hello signal. You need to use the correct type in GetNode<Type>()

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.