Hey guys, I am really lost. For a tremendous amount of time I am trying to connect signal in c# including binds. I am currently on v3.3.1stable.mono.official.

Godot refuses to find method to run yelling at me with: E 0:00:01.380 emit_signal: Error calling method from signal 'body_entered': 'Node2D(Map.cs)::onBodyAreaEntered': Method not found.. <C++ Source> core/object.cpp:1257 @ emit_signal()

I've read all the corresponding issues on github and I am convinced this error means arguments of my connected method onBodyAreaEntered are not correctly typed (or are in wrong number). But I am not able to figure how to correct them, I've tried many combinations of (Node body, params string[] area) (Node2D body, string area) (object body, object[] area) And much more, including Arrays, Collections and I don't know..

If I remove highlighted binds parts, signal works just fine. May anybody help me, please? Many thanks..

Welcome to the forums @Reloecc!

Have you tried passing the value directly without being in an array? The documentation shows it being done this way, though I have never tried it myself so I'm not positive it will work. Adapting the documentation style, something like this may work:

public class Map: Node2D
{
	public const string AREA_MINES = "Mines"
	
	public override void _Ready() {
		(GetNode("City")?.GetNode("objects/area_mines") as Area2D)
			?.Connect("body_entered", this, nameof(onBodyAreaEntered), AREA_MINES));
	}
	
	protected void onBodyAreaEntered(object body, string area) {
		if (body is Player player)
			player.onAreaEntered(area);
	}
}

@TwistedTwigleg said: Have you tried passing the value directly without being in an array?

I did right now, code is unbuildable because of incompatible types. You know.. c# is typed, it's not like a gdscript :)

--

Thank you for welcoming me in forum, I've actually got my account deleted because of db corruption last year (as I have found out today), I am not really new here, but appreciated.

@Reloecc said:

@TwistedTwigleg said: Have you tried passing the value directly without being in an array?

I did right now, code is unbuildable because of incompatibility types. You know.. c# is typed, it's not like a gdscript :)

Ah okay. They are both Strings, so in theory it should be compatible, but I wonder if the const is making it not work, as I suppose a constant string is different than a string.

I'll do some tests tomorrow and see if I can get something working :smile:

Thank you for welcoming me in forum, I've actually got my account deleted because of db corruption last year (as I have found out today), I am not really new here, but appreciated.

Ah! Well in that case: welcome back to the forums then! :smiley:

@TwistedTwigleg said: Ah okay. They are both Strings, so in theory it should be compatible..

I am sorry, but.. that's not where the type fails to match. It's about the function Node::Connect. The argument Array binds is not compatible with a string (nor String).

I'll do some tests tomorrow and see if I can get something working Appreciated, thank you.

Hi, I also experienced difficulties to use signals with data in c#.

More precisely, I could only get it working in the case when the data is a "basic" type. But something like this worked:

   int  invalueToPass = ...;
                button.Connect( "pressed" , this, "MyFunction",
                 new Godot.Collections.Array() {invalueToPass } );

where MyFunction takes a "int" as input. While it may be ugly, I am sure you can find a way to map this int to arbitrary data in "MyFunction ".

@alex_sand said: But something like this worked: new Godot.Collections.Array() {invalueToPass } );

Ah.. I've mad a huge mistake confusing brackets in godot Array declaration.

Correct is: new Array { AREA_MINES }

Instead of new Array ( AREA_MINES )

Thank you for indirectly pointing me to the way.

2 years later