How to call a static GDScript method into a C# file

Godot Version

4.5.1 .NET version

Question

Hello everyone ! I’m new on Godot, and I am slowly but surely taking my marks here. As I am already a bit familiar with C#, I decided to go there for my game. When I started to watch a tutorial, the one making the video gave some tools to help, Godot-Helper-Script made in GDScript

I watched the Cross Language documentation and even if I understood a good part of it, one thing that ticks me is : if the method we want to call is static, how do we do this precisely ?

To illustrate, let’s imagine this :

vectors.gd

class_name Vectors extends Node

static func get_four_direction_vector(diagonal_allowed: bool) -> Vector2:
	var velocity: Vector2 = Vector2.ZERO
	...
	...
	return velocity

myScript.cs (or at least what I would need)

public void Method(){
    Vector2 movement = Vector.get_four_direction_vector(false);
}

I probable have to load the script file, but how can I have Vector and not an instance of Vector ?

Thank you in advance :grin:

Yes, you load the class, then use class.Call(“methodname”).

A friendly advice, you might want to consider switching to GDScript if you havent stuck too deep yet. C# is not exactly a first class citizen in Godot, using it adds some headache in 3.6, and it is only more limited in 4. It is supposed to be quite a bit faster, but unless you are going to be doing alot of calculations the ease of GDScript might be more preferable. I am considering leaving C# behind once I am done with my 3.6 project.

Do you have a source for this? Aside from web export not being available, C# support have only gotten better and better since godot 3.

1 Like

Haven’t researched other possible obstacles. Not being able to export to one of the platforms alone is a deal breaker for me.

Thanks for the advice !

As for the C# thing, I do need some heavy calculations (Minimax Alpha-beta), and I already have an entire C# project ready for it (I tried using GameMaker at first for my game, but I couldn’t use the .dll in a way it could also be used on Linux, so I decided to switch to Godot)