[C#] How do you access variables from a GDScript in your C# code?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Wibbly

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.

:bust_in_silhouette: Reply From: Zylann

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);