I had two classes in my game, Player and ShootableObject. Both set up as such:
class Player : public RigidBody2D { private: GDCLASS(Player, RigidBody2D); ... implementation follows ... class ShootableObject : public RigidBody2D { private: GDCLASS(ShootableObject , RigidBody2D); ... implementation follows ... And registered as such in my module:
void initialize_example_module(godot::ModuleInitializationLevel p_level) { if (p_level != godot::MODULE_INITIALIZATION_LEVEL_SCENE) { return; } godot::ClassDB::register_class<godot::Player>(); godot::ClassDB::register_class<godot::ShootableObject>(); } I wanted to extract some common behavior from the two and created a third class, as such:
class GravityBody2D : public RigidBody2D { private: GDCLASS(GravityBody2D, RigidBody2D); I then changed the inheritance of the other two:
class Player : public GravityBody2D { private: GDCLASS(Player, GravityBody2D); ... implementation follows ... And added it to the exports:
void initialize_example_module(godot::ModuleInitializationLevel p_level) { if (p_level != godot::MODULE_INITIALIZATION_LEVEL_SCENE) { return; } godot::ClassDB::register_class<godot::Player>(); godot::ClassDB::register_class<godot::ShootableObject>(); godot::ClassDB::register_class<godot::GravityBody2D>(); } I now get an error that the classes are not found:
Cannot get class 'Player'. Cannot get class 'ShootableObject'. Cannot get class 'ShootableObject'. I can however see GravityBody2D in the node list:
How can I inherit my own class?
