GDExtension multiple inheritance

Godot Version

4.2.2 Mono

Question

I’m writing a class that defines a custom type derived from BaseButton, and I wanted it to modify the transformation of its first child node, so I figured I’d inherit both BaseButton and Container, however, this gives me an ambiguity error when defining GDCLASS.

Is it even possible to have multiple inheritance in GDExtension? Thanks!

1 Like

No because most godot classes derive from a single ancestry. You get the diamond problem.

1 Like

That will be difficulty for godot to handle:
your class inherits from Node and Resource, is it a Node or a Resource? Can’t be both.

In general I follow composition over inheritance.
I only use inheritance when it’s necessary or when it makes things way more convenient to use.

Most of the time I try to stick with composition (especially in godot) because that’s the easiest way to make your stuff reusable.

I would recommend finding a solution that’s based on composing your desired behavior.