[ad_1]
I had two lessons in my recreation, Participant
and ShootableObject
. Each arrange as such:
class Participant : public RigidBody2D
{
personal:
GDCLASS(Participant, RigidBody2D);
... implementation follows ...
class ShootableObject : public RigidBody2D
{
personal:
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::Participant>();
godot::ClassDB::register_class<godot::ShootableObject>();
}
I wished to extract some widespread conduct from the 2 and created a 3rd class, as such:
class GravityBody2D : public RigidBody2D
{
personal:
GDCLASS(GravityBody2D, RigidBody2D);
I then modified the inheritance of the opposite two:
class Participant : public GravityBody2D
{
personal:
GDCLASS(Participant, 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::Participant>();
godot::ClassDB::register_class<godot::ShootableObject>();
godot::ClassDB::register_class<godot::GravityBody2D>();
}
I now get an error that the lessons will not be discovered:
Can not get class 'Participant'.
Can not get class 'ShootableObject'.
Can not get class 'ShootableObject'.
I can nevertheless see GravityBody2D
within the node record:
How can I inherit my very own class?
[ad_2]