If you want to use a GDNative library in Godot from a C# script, here’s how you do it. I’ll use the Oculus Mobile plugin as an example:

1
2
3
4
5
6
// Load the GDNative Library resource
NativeScript initLib = GD.Load<NativeScript>("res://addons/godot_oculus_mobile/OvrInitConfig.gdns");
// Initialize the library into a GDScript object
Reference ovrInit = (Reference)initLib.New();
// Call a function in the GDNative library with an argument
ovrInit.Call("set_render_target_size_multiplier", 1);

You can also retrieve the return value by just casting it to the approriate Godot type:

1
2
3
4
5
6
// Load the GDNative Library resource
NativeScript guardianLib = GD.Load<NativeScript>("res://addons/godot_oculus_mobile/OvrGuardian.gdns");
// Initialize the library into a GDScript object
Reference ovrGuardian = (Reference)guardianLib.New();
// Call a function and cast the return value
Godot.Collections.Array points = (Godot.Collections.Array)ovrGuardian.Call("get_boundary_geometry");

As with any other function call into the Godot C# library, you must make sure the types going in and out of the functions are from the Godot library, not higher-level C# types (like System.Collections.Dictionary). For people used to programming in other engines with C#, this setup can seem a little clunky. However, one benefit I think this model has is that it makes the fact that all these calls go through GDScript, and not directly to lower-level engine modules, very explicit. This can be important when reasoning about performance in your code, and helps ensure heavy computations in C# reduce GD calls as much as possible and don’t have these calls in critical paths, if it can be avoided.