C# class in GdScript (cross language scripting)

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

I can’t “import” a C # class into godot. I think I forgot about something, but I can’t find more information in the documentation.
I have created a class in c # in visual studio, and I wanted to be able to call its methods from Gdscipt.

I have found this material in the documentation, I should simply write this and it will load:

var my_csharp_script = load ("res: //csharpclass/myClass.cs")
var my_csharp_node = my_csharp_script.new ()
print (my_csharp_node.str2) # barbar

In this case, my_csharp_script is null, and I don’t understand why (I have myClass.cs in this folder correctly). The only thing I observe is that I cannot see my cs file from Godot’s explorer, which I don’t know if it is normal, or I need to configure something else for all this to work.

You need to show the C# and/or output window. I suspect your class name differs from your script name; this should show in the debugger. You also have an extra space after res: in the string you’re passing to load. The file should show in godot’s explorer - it’s worth confirming it is in the correct location.

You’ve likely seen the documentation:

Cross-language scripting — Godot Engine (stable) documentation in English

spaceyjase | 2021-12-11 14:53