C# Inheritance - script inheritance from another script (attached to another node)

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

I’m new to Godot, so the issue here is probably that I don’t understand an element of how things work, but I would appreciate any help/explanations.

My understanding is (based on the docs and various tutorials) if you’re working in GDScript, when you attach a script to a node you can inherit from either a standard node type (e.g. Node2D, KinematicBody2D etc.) or from an existing script attached to a specific node instance (e.g. World).

My issue is, I don’t seem to be able to do the latter in C#. In the Godot GUI, when I go to ‘Attach Node Script’ the button is greyed out when you choose C# from the dropdown.

If I enter a path to the C# script in the ‘Inherits’ box, it tells me that this is an invalid parent name or path (even when the script (in the example case ‘World.cs’) definitely exists).

I can create a script that inherits from, for instance, “Node2D” and then overwrite the inheritance relationship in the script:

public class myNode : World

but this doesn’t seem to behave correctly at runtime (I suspect because the engine isn’t aware of the inheritance relationship).

Is this intentional/a limitation/an intended feature? Is there another way to do this with C# in Godot that I’m missing? Is there something key that I’m misunderstanding? If anyone can help out it would be much appreciated.

I have the same problem :confused:

Pedro Lucas | 2020-12-29 19:37

This may be much too late to be of any use, but for future reference my issue was solved here: Reddit - Dive into anything. The problem was me not understanding C# inheritance correctly and was not an engine issue!

madeofst | 2022-01-23 11:43