You can define and derive from any abstract class you define, as long as any of your superclasses is a godot class.
This allows you to define default functions for your inheriting classes and override them in some, but not all subclasses if you want.
You can define a abstract class and register it's members the same way as you do for normal classes.
Under the hood, we only register your normal classes, and let them register all members your abstract class defines.
Info
For this reason, the @RegisterClass
annotation is optional for abstract classes.
Warning
As in kotlin, you cannot instantiate abstract classes directly from any other scripting language like GDScript! In fact, godot does not even know (or care) that your abstract class exists.
Example
Abstract class definition:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Child class definition:
1 2 3 4 5 6 7 |
|
Registration of overridden members
As you can see in the example; you need to explicitly register any member in the child class which you override from the abstract parent class. Otherwise they will not be registered and thus are not known to godot.