godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.6k stars 21.1k forks source link

(C#) Limitations using Collections and Arrays with signals #66401

Open LasOz opened 2 years ago

LasOz commented 2 years ago

Godot version

v3.4.5.stable.mono.official [f9ac000d5]

System information

Windows 10

Issue description

I tried to set up a signal that would pass an IEnumerable<Rect2> to the receiver, however when trying to do this the Enumerable was empty according to the receiver. I investigated to ensure the Enumerable was not empty upon Emit.

//Inside emitter class
[Signal]
public delegate void SelectionMade(IEnumerable<Rect2> squares);

//Inside receiver class
private void _on_GameManager_SelectionMade(IEnumerable<Rect2> squares)
{
    SelectionSquares = squares;
    Update();
}

After this I tried changing the type of the signal's parameters (and receiving method) and noticed inconsistent behaviour with the use of arrays.

The following is perfectly functional and results in desired behaviour with no warnings or errors.

//Inside emitter class
[Signal]
public delegate void SelectionMade(int[] squares);

//Inside receiver class
private void _on_GameManager_SelectionMade(int[] squares)
{
    Console.WriteLine(squares);
    Update();
}

However changing the array type from int[] to double[] results in the following errors:

//Inside emitter class
[Signal]
public delegate void SelectionMade(double[] squares);

//Inside receiver class
private void _on_GameManager_SelectionMade(double[] squares)
{
    Console.WriteLine(squares);
    Update();
}
E 0:00:00.880   _get_signal: Unknown type of signal parameter: 'squares' in 'GameManager'.
  <C++ Source>  modules/mono/csharp_script.cpp:2506 @ _get_signal()

I tried a primitive array with the following primitive types:

Steps to reproduce

I have attached a repro project, which consists of only two source files and two classes.

There is only a single signal used which is connected via the _Ready() method of the Emitter class.

Simply running the game should be enough to reproduce the issue.

To try different Array and Collection types simply change:

Minimal reproduction project

[Uploading Repro.zip…]()

LasOz commented 2 years ago

Repro.zip The repro project didn't seem to upload properly on the original post. Hopefully this repro uploads.