+1 vote

I am creating a game with chunk based generation like in Minecraft (but in 2D). I decided to change that part of the code to C# so I could get some performance improvements and use Threads in C# so I can make the process feel a bit smoother in-game.
I'm experienced with C#, but never used it with Godot.
There's a part in my GDScript code where I store all my Player instances so I can get some info about their current chunk later (I use class_name Player).

Problem is: How can I do that in C#? Can you reference a .gd "class" type the same way you can do it inside GDScript? I'm using Visual Code.

asked Sep 27, 2019 in Engine by Wibbly (29 points)

1 Answer

+3 votes

To interoperate with GDScript from C#, you have to use Godot's generic functions from Godot.Object (a bit like reflection) because there are no actual C# functions and variables you can use.

So to call a function, it would be like this:

Node node = GetNode("Node/With/Your/Script/On/It")
node.Call("function_name", argument1, argument2);

Getting and setting variables:

Vector3 v = (Vector3)node.Get("variable_name");

node.Set("variable_name", value);
answered Sep 28, 2019 by Zylann (26,045 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.