Inheritence in GD script

Godot Version

Godot Version 4.2.2 Stable

Question

I was wondering if there was a way to implement inheritance/interfaces in GD script, similar to the languages c# and java

Yes you can extend classes, it is a requirement for scripts as far as I know

extends CharacterBody3D
class_name Player

You can extend any attached script by right clicking a scripted node and selecting “Extend Script…”

There is no interface mechanism and the workarounds imo aren’t very good.
There is not likely to be interfaces in the near future.
There is a traits system coming and you can read about it here.

Besides that, it can include method signatures, which are methods without an implementation defined, making the trait acting like an interface.

how many classes can you extend

All of the built-in classes and any built on top of them, for as far down the chain as you want. I do not believe multiple inheritance is added, but it is so rarely sought after

1 Like