I recently got intrigued to use C# in my Godot 3.5.1 projects along GDScript which I feel being superior in integration with the engine. I created a computational heavy procedural generation gdscript and it takes around 50 seconds to complete. That is "okayish", but out of curiosity I want to reimplement it in C# to see how much it could gain from being compiled by Mono, since the algorithm as such doesn't use any GD calls, just crunches numbers on internal data, which should be faster by up to 4 times, only the result would be given out to gdscript.
Okay, right now I'm trying to find the best ways to connect the gdscript and the mono world. The documentation says cross language developing is fully supported.
Right now, I'm still exploring, so my example might not make much sense yet, but for example I created a Array3D.cs class to support 3D Arrays, it looks a little something like this:
public class Array3D : Reference
{
private object[,,] data = new object[0,0,0];
public Array3D(int p_x_size, int p_y_size, int p_z_size)
{
clearAndResize(p_x_size, p_y_size, p_z_size);
}
(additional code ommitted)
Then in my gdscript I'll tried and managed to import my script and start using it, but it doesn't work:
const Array3D:CSharpScript = preload("res://tools/mono/Array3D.cs")
var exampleData:Array3D = Array3D.new(10, 10, 10)
The error is: "Too many arguments for "_init()" call. Expected at most 0.
I know, a workaround would be to make the constructor parameterless, then init it manually later. But the official documentation promises differently:
https://docs.godotengine.org/en/stable/classes/class_csharpscript.html
It clearly states multiple arguments, just like for other gdscripts:
Variant new ( ... ) vararg
So is there a way to make that work?
I'm also a little discouraged to use a cross language scripting right now, I expected it be much more integrated. I didn't expect that I need to import C# classes with load(), I expected them to be available in namespace just like gdscript classes with a name.