0 votes

Hi

I am trying to send a signal from C++ using native plugin. I have managed to send a signal with any of the defined data classes like int, string, color etc however I cannot figure out a way to send signal with a custom object.

I have realised that it is possible to send a signal of any Variant, and Variant constructor accepts type Object but I cannot find any example how to do it.

class MyData : public Object {
}

class Simple : public GodotScript<Reference> {
GODOT_CLASS(Simple); 
public:
    void _init() override {
         owner->add_user_signal("mySignal");
    }
    void say() {
         owner->emit_signal("mySignal", new MyData());
    }
    static void _register_methods() {
         register_method("say", &Simple::say);
    }
}

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<Simple>();
}

I have tried to wrap MyData object in GodotScript, use macros GODOTCLASS , GODOTSUBCLASS. When I run the code I either have null instance when called ".new" so something is wrong with library or object from signal is null or its just "Object" with no way to cast it to my object.

Additionally is there anyway to see more detailed log of error in godot for loaded libraries?

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

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.