Skip to content

Using the toolkit with C#

Holger Dammertz edited this page Jun 2, 2020 · 1 revision

The whole toolkit is written in GDScript. It is still possible to use it with a project based on C# as godot allows to call gdscript functions and set gdscript variables from within C#. This wiki page should give you some hints on how this can be achieved. If you are working on a C# project and are using the toolkit you can help extending this section for others if you have suggestions or tips.

To initialize the global singleton you can use

if (GetTree().Root.HasNode("vr"))
{
   Node vr = GetTree().Root.GetNode("vr");            
   vr.Call("initialize");
}

and call the necessary GDScript function.

Below are more general code snippets. Th code there is based on two answers from https://godotengine.org/qa/52761/c%23-how-do-you-access-variables-from-a-gdscript-in-your-c%23-code and https://gamedev.stackexchange.com/questions/169190/how-can-i-reference-c-objects-in-gdscript-and-vice-versa

Calling functions:

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

Getting/Setting variables:

Node node = GetNode("Node/With/Your/Script/On/It")
Vector3 v = (Vector3)node.Get("variable_name");
node.Set("variable_name", value);