Calling GDExtension Classes from C#

Godot Version

Godot 4.2

Question

I’m currently working on a GDExtension in order to generate audio stream previews similar to the ones used in the audio import dialog in the editor. I have the extension fully compiled and my new AudioPreviewGenerator shows up in the ClassDB (as I can add the node to a scene no problem) but when I try to reference it from my C# code it pops up the dreaded CS0246: The type or namespace name 'AudioPreviewGenerator' could not be found (are you missing a using directive or an assembly reference?) error. From what I’ve found learning C# in Godot so far it seems like C# interaction is somewhat fraught, so is this something I can fix, a known C#-exclusive issue, or a bigger misunderstanding of the GDExtension system?

The code for my extension can be found here (in Swift because it’s the only language that has working GDExtension support that I know well enough to write), and my C# class has the template using Godot; using System; imports with nothing else.

Edit: If as I suspect C# doesn’t pick up on new ClassLib classes from GDExtension automatically, I’m planning to just add wrapper classes that use call to access all the requisite methods. Is there some smarter/better way of doing that then bundling in .cs files for use or should I just stick with that?

GDExtensions are awful to work with when using C#. Makes it hard for me to accept C# having “first class support” :frowning_face:

It’s not impossible, however. You have to use ClassDB and strings, see Terrain3D’s docs for an example.

Yeah, that’s about what I expected. I’m just gonna make a wrapper type that does all the ClassDB calls for you. Thank you!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.