Godot Version
4.1.4
Issue
I made an GDExtension-library containing a base class (CharacterComponent). When trying to implement another extension (DefaultGravity) that builds on the first one I encountered two issues.
- I could not include the header file from the base class, so I had to copy header and implementation into my DefaultGravity directory
- My Child class of the second extension does not show the added property from the parents _bind_methods().
Questions
How do you link remote custom headers and how to properly inherit added properties of a parent class?
Code - Short Version
void godot::DefaultGravity::_bind_methods(){
ClassDB::bind_method(D_METHOD("get_gravity_factor"), &DefaultGravity::get_GravityFactor);
ClassDB::bind_method(D_METHOD("set_gravity_factor", "gravity_factor"), &DefaultGravity::set_GravityFactor);
ClassDB::add_property("DefaultGravity",PropertyInfo(Variant::FLOAT, "Gravity Factor"), "set_gravity_factor", "get_gravity_factor");
}
I tried these three approaches to get my child node to adopt its parent nodes added property. The extension compiled but in the editor only the factor property is shown.
CharacterComponent::_bind_methods();
ClassDB::bind_method(D_METHOD("get_target"), &DefaultGravity::get_Target);
ClassDB::bind_method(D_METHOD("set_target", "target"), &DefaultGravity::set_Target);
ClassDB::add_property("DefaultGravity",PropertyInfo(Variant::OBJECT, "Target Character", PROPERTY_HINT_NODE_TYPE, "CharacterBody3D", PROPERTY_USAGE_DEFAULT), "set_target", "get_target");
}
ClassDB::bind_method(D_METHOD("get_target"), &CharacterComponent::get_Target);
ClassDB::bind_method(D_METHOD("set_target", "target"), &CharacterComponent::set_Target);
ClassDB::add_property("CharacterComponent",PropertyInfo(Variant::OBJECT, "Target Character", PROPERTY_HINT_NODE_TYPE, "CharacterBody3D", PROPERTY_USAGE_DEFAULT), "set_target", "get_target");
}
Complete Code
CharacterComponent.h
#ifndef CHARACTER_COMPONENT
#define CHARACTER_COMPONENT
#include <godot_cpp/classes/node.hpp>
#include <godot_cpp/classes/character_body3d.hpp>
namespace godot{
class CharacterComponent : public Node{
GDCLASS(CharacterComponent, Node)
private:
CharacterBody3D* target;
protected:
static void _bind_methods();
public:
CharacterComponent();
~CharacterComponent();
CharacterBody3D* get_Target() const;
void set_Target(CharacterBody3D* target_cb);
};
}
#endif
CharacterComponent.cpp
#include "CharacterComponent.h"
#include <godot_cpp/classes/character_body3d.hpp>
using namespace godot;
void CharacterComponent::_bind_methods(){
ClassDB::bind_method(D_METHOD("get_target"), &CharacterComponent::get_Target);
ClassDB::bind_method(D_METHOD("set_target", "target"), &CharacterComponent::set_Target);
ClassDB::add_property("CharacterComponent",PropertyInfo(Variant::OBJECT, "Target Character", PROPERTY_HINT_NODE_TYPE, "CharacterBody3D", PROPERTY_USAGE_DEFAULT), "set_target", "get_target");
}
CharacterComponent::CharacterComponent(){
}
CharacterComponent::~CharacterComponent(){
}
CharacterBody3D *godot::CharacterComponent::get_Target() const{
return target;
}
void CharacterComponent::set_Target(CharacterBody3D *target_cb){
this->target = target_cb;
}
DefaultGravity.h
#ifndef DEFAULT_GRAVITY
#define DEFAULT_GRAVITY
#include <CharacterComponent.h>
namespace godot{
class DefaultGravity : public CharacterComponent{
GDCLASS(DefaultGravity, CharacterComponent)
private:
float custom_gravity_factor;
protected:
static void _bind_methods();
public:
DefaultGravity();
~DefaultGravity();
float get_GravityFactor() const;
void set_GravityFactor(float gravity_f);
};
}
#endif
DefaultGravity.cpp
#include "DefaultGravity.h"
using namespace godot;
void DefaultGravity::_bind_methods(){
//CharacterComponent::_bind_methods();
ClassDB::bind_method(D_METHOD("get_gravity_factor"), &DefaultGravity::get_GravityFactor);
ClassDB::bind_method(D_METHOD("set_gravity_factor", "gravity_factor"), &DefaultGravity::set_GravityFactor);
ClassDB::add_property("DefaultGravity",PropertyInfo(Variant::FLOAT, "Gravity Factor"), "set_gravity_factor", "get_gravity_factor");
ClassDB::bind_method(D_METHOD("get_target"), &DefaultGravity::get_Target);
ClassDB::bind_method(D_METHOD("set_target", "target"), &DefaultGravity::set_Target);
ClassDB::add_property("DefaultGravity",PropertyInfo(Variant::OBJECT, "Target Character", PROPERTY_HINT_NODE_TYPE, "CharacterBody3D", PROPERTY_USAGE_DEFAULT), "set_target", "get_target");
}
DefaultGravity::DefaultGravity(){
CharacterComponent();
}
DefaultGravity::~DefaultGravity(){
}
float DefaultGravity::get_GravityFactor() const{
return custom_gravity_factor;
}
void DefaultGravity::set_GravityFactor(float gravity_f){
this->custom_gravity_factor = gravity_f;
}