Could not resolve super class inheritance (c#)

Godot Version

v4.2.1.stable.mono.official

Question

This question I am posting here just in case I missed something obvious. As far as I can tell, GDscript cannot extend a c# class. The only alternative I found is: var v_csharpclass : CsharpClass = CsharpClass.new()




Below are two test classes that I want to extend.

The first in GDscript and the second in c#. This works fine:

#
# GdscriptClass.gd
#
extends Node
class_name GdscriptClass
static var HELLO_GDSCRIPT : String = "Hello, GD Script!"



This doesn’t work. If I try to extend this c# class from gdscript, it tell me: Could not resolve super class inheritance from “CsharpClass”

//
// CsharpClass.cs
//
using Godot;
[Godot.GlobalClass]
public partial class CsharpClass:Node {
	[Signal]
	public delegate void HelloSignalEventHandler();
	public CsharpClass() {
		Connect(SignalName.HelloSignal, Callable.From(() => {
			GD.Print("Hello, signal!");
		}));
	}
	public override Variant _Get(StringName a_property) {
		if("HELLO_CSHARP" == a_property) {
			return Variant.CreateFrom("Hello, C#");
		}
		return base.Get(a_property);
	}
}



Below are the three test GDscripts.

First is a gdscript extending another class created in gdscript. No issues!

#
# GdscriptClass.gd
#
extends Node
class_name GdscriptClass
static var HELLO_GDSCRIPT : String = "Hello, GD Script!"



The second test new()'s a c# class from gdscript. From there I do a property/signal test. This test works.

extends Node
func _init() -> void:
	var v_csharpclass : CsharpClass = CsharpClass.new()
	print (v_csharpclass.HELLO_CSHARP, " <-- CsharpClass.new().HELLO_CSHARP")
	v_csharpclass.emit_signal("HelloSignal")



My heart is crushed, I want to do this, but the GD gods have denied me:

extends CsharpClass

This is the error I get:

Line 1:Could not resolve super class inheritance from "CsharpClass".



Thank you for reading this post. Cheers!

1 Like

This is simply not possible, as explained in the last paragraph of the documentation page you linked.

A GDScript file may not inherit from a C# script. Likewise, a C# script may not inherit from a GDScript file.