godotengine / godot-docs

Godot Engine official documentation
https://docs.godotengine.org
Other
3.78k stars 3.07k forks source link

Missing example to connect signal in GDNative C++ code #3360

Open jumpy88 opened 4 years ago

jumpy88 commented 4 years ago

I've read and replicated the example described in gdnative-cpp-example.rst but I can't successfully connect a function to a signal in C++ source code. It just says some_other_node->connect("the_signal", this, "my_method"); I tried to add get_node("Reset")->connect("pressed", this, "on_Reset_pressed"); in both _init and _ready. In the first case it returns an error because it can't find the node (Reset is a Button) and the second doesn't seem to do anything. Where should I put the connect call?

jumpy88 commented 4 years ago

There is no one who can provide any information/advice about this?

jumpy88 commented 4 years ago

I've solved it: _ready is the right place for get_node(NodePath("/root/Main/Reset"))->connect("pressed", this, "on_Reset_pressed"); call, but I was missing the required _ready method registration in _register_methods register_method("_ready", &GDExample::_ready); I think it makes sense to leave this issue open because C++ GDNative tutorial still should be improved including a signal connection example.

Thanks @karroffel for your help addressing this issue.

Noah-shn commented 3 years ago

@jumpy88 can you please, provide me the example you used to make it run, I've been stuck at making the signal from the doc work !

jumpy88 commented 3 years ago

Hello @Noah-shn, sorry for the delay but I'm a little busy in this period. I need some free time to organize a repository with a full example. I hope I can do it by the next weekend. In the meantime, at which point are you stuck? Did you try the solution described here? See you soon.