Godot Version
4.3
Question
I am making a module, and I have a class where one of the exposed methods takes another class in that same module as an argument. When I compile Godot, I get an error that the type is not recognized and can’t be used.
If I swap the type for the exposed method to something like String, or some other Godot type, it works fine, so I know it is just this custom class type that is causing the issue. Is this possible? Or would I need to make some engine changes to allow for exposing custom types for a module’s API? Below will be an example of the classes and register_types.cpp
// MyClass.h
#ifndef MY_CLASS_H
#define MY_CLASS_H
#include "core/object/object.h"
#include "core/object/ref_counted.h"
class MyClass : public Object {
GDCLASS(MyClass, Object);
protected:
String data;
static void _bind_methods() {
ClassDB::bind_method(D_METHOD("set_data", "data"), &MyClass::set_data);
ClassDB::bind_method(D_METHOD("get_data"), &MyClass::get_data);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_data", "get_data");
}
void set_data(const String &data) {
this->data = data;
}
String get_data() const {
return data;
}
public:
MyClass() {};
};
#endif // SUMMATOR_H
// ExposedClass.cpp
#include "ExposedClass.h"
ExposedClass::ExposedClass() {}
// The exposed types have to be godot types.
void ExposedClass::custom_method(MyClass msg) {
// Do stuff
}
void ExposedClass::_bind_methods() {
ClassDB::bind_method(D_METHOD("custom_method", "msg"), &ExposedClass::custom_method);
}
// register_types.cpp
#include "register_types.h"
#include "core/object/class_db.h"
#include "MyClass.h"
#include "ExposedClass.h"
void initialize_my_module_module(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
return;
}
ClassDB::register_class<MyClass>();
ClassDB::register_class<ExposedClass>();
}
void uninitialize_my_module_module(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
return;
}
// Nothing to do here in this example.
}
With a setup similar to the one above, it will fail compilation with:
./core/variant/binder_common.h:690:40: error: incomplete type 'GetTypeInfo<MyClass, void>' used in nested name specifier
690 | type = GetTypeInfo<Q>::VARIANT_TYPE;
I have tried going through and adding my type within the whole variant system, and I can kind of get it working, but it is a lot of changes in the engine to get it working. I would rather have it all contained in this or another module if possible, or if this is possible with gdextensions, I would be fine with something like that as well.
Thanks for any help!