NeoSpark314/godot_oculus_quest_toolkit

C# bindings

knochenhans opened this issue · 5 comments

Hi, I’m still new to Godot so I might have overlooked something. Seems though the only way to use the toolkit right now is via GDScript. Thus, it would be great to make the classes etc. available for C# scripts as well.

The whole toolkit is written in GDScript. I do not know if it is possible to call GDScript code from C# since I have never used C# in godot. Do you know someone with Godot C# experience who could answer this? Perhaps you can still call functions on nodes even if they are implemented via GDScript. In this case you should be able to call for example all functions on the global vr singleton (and all other nodes) and the full functionality should be available already to C#

As far as I understand the Godot docs, mixing is possible between nodes and there is even a way to call GDScript functions from C#. This only seems to work for internal functions, though, not member functions from the vr package. But I’ll give your singleton idea a try, or maybe ask someone with more Godot + C# experience :)

I just found these two questions with answers: 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

It seems possible to call arbitrary gd script functions. You first need to get/find the node by name and then can Call a gdscript function. If this works the whole toolkit would be usable from C#; that would be great. If you can try it and it works we should add a wiki entry that explains how to do it.

Thanks, the following code works fine to initialize the toolkit from a C# script:

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

It’s not exactly a convenient solution as it makes things like IntelliSense impossible but I guess writing a C# wrapper class (or classes) for the toolkit would end up rewriting the whole toolkit in C# ^^

Yes; and it probably is not necessary for the most projects. At least in my projects I end up calling only very few functions of the vr singleton in most cases. And the plan for the toolkit is to make it customizable directly from the editor for the most common cases.

I created a short wiki page now that documents the findings so far: https://github.com/NeoSpark314/godot_oculus_quest_toolkit/wiki/Using-the-toolkit-with-C%23