+3 votes

I have managed to setup my project with help of https://gamedevadventures.posthaven.com/

However I got stacked when I linked my c++ code with godot plugin. I can't find a way to return my custom class to Godot.

class MyClass {

}

class Simple : public GodotScript<Reference> {
GODOT_CLASS(Simple);
  void say(String message) {
        Godot::print(message);
    }
    String hello(String target) {
        return String("Hello you, {0}!").format(Array::make(target));
    }
    MyClass getMyClass() {
      return MyClass();
    }
   static void _register_methods() {
        register_method("say", &Simple::say);
        register_method("hello", &Simple::hello);
        register_method("myClass", &Simple::getMyClass);
    }
}

extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) {
    Godot::gdnative_init(o);
}

extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *o) {
    Godot::gdnative_terminate(o);
}

extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) {
    Godot::nativescript_init(handle);
    register_class<MyClass>();
    register_class<Simple>();
}

When i run it i get these error

error: ‘___get_type_name’ is not a member of ‘MyClass’
  godot::nativescript_api->godot_nativescript_register_class(godot::_RegisterState::nativescript_handle, T::___get_type_name(), T::___get_base_type_name(), create, destroy);

and many more with __getbasetypename, registermethods

How do I register a custom class with godot plugin? If i replace MyClass with Dictionary for example its not a problem.

Thanks for help

asked Jun 3, 2018 in Engine by mikekulasinski (26 points)

I assume that you must use the Godot base classes, like Object or Node, becuase your class seems to lack a default propertiy.
I howhaver have never acutally worked with GDNative, I've only read about it.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.