Up to date

This page is up to date for Godot 4.1. If you still find outdated information, please open an issue.

Cross-language scripting

Godot allows you to mix and match scripting languages to suit your needs. This means a single project can define nodes in both C# and GDScript. This page will go through the possible interactions between two nodes written in different languages.

The following two scripts will be used as references throughout this page.

extends Node

var my_field: String = "foo"

func print_node_name(node: Node) -> void:

func print_array(arr: Array) -> void:
    for element in arr:

func print_n_times(msg: String, n: int) -> void:
    for i in range(n):

Instantiating nodes

If you're not using nodes from the scene tree, you'll probably want to instantiate nodes directly from the code.

Instantiating C# nodes from GDScript

Using C# from GDScript doesn't need much work. Once loaded (see Classes as resources), the script can be instantiated with new().

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


When creating .cs scripts, you should always keep in mind that the class Godot will use is the one named like the .cs file itself. If that class does not exist in the file, you'll see the following error: Invalid call. Nonexistent function `new` in base.

For example, MyCoolNode.cs should contain a class named MyCoolNode.

The C# class needs to derive a Godot class, for example GodotObject. Otherwise, the same error will occur.

You also need to check your .cs file is referenced in the project's .csproj file. Otherwise, the same error will occur.

Instantiating GDScript nodes from C#

From the C# side, everything work the same way. Once loaded, the GDScript can be instantiated with GDScript.New().

GDScript MyGDScript = (GDScript)GD.Load("res://path_to_gd_file.gd");
GodotObject myGDScriptNode =