Skip to content

Commit 5110c2d

Browse files
Zacrainmhilbrunnerdsnopek
authored
Fix GDExample C++ signal connect example and add explanation (godotengine#8381)
* Fix signal connect example, add explanation * Update tutorials/scripting/gdextension/gdextension_cpp_example.rst Co-authored-by: David Snopek <[email protected]> * Update tutorials/scripting/gdextension/gdextension_cpp_example.rst --------- Co-authored-by: Max Hilbrunner <[email protected]> Co-authored-by: David Snopek <[email protected]>
1 parent ef633e9 commit 5110c2d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

tutorials/scripting/gdextension/gdextension_cpp_example.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,21 @@ This is the required syntax:
596596

597597
.. code-block:: cpp
598598
599-
some_other_node->connect("the_signal", this, "my_method");
599+
some_other_node->connect("the_signal", Callable(this, "my_method"));
600+
601+
To connect our signal ``the_signal`` from some other node with our method
602+
``my_method``, we need to provide the ``connect`` method with the name of the signal
603+
and a ``Callable``. The ``Callable`` holds information about an object on which a method
604+
can be called. In our case, it associates our current object instance ``this`` with the
605+
method ``my_method`` of the object. Then the ``connect`` method will add this to the
606+
observers of ``the_signal``. Whenever ``the_signal`` is now emitted, Godot knows which
607+
method of which object it needs to call.
600608

601609
Note that you can only call ``my_method`` if you've previously registered it in
602-
your ``_bind_methods`` method.
610+
your ``_bind_methods`` method. Otherwise Godot will not know about the existence
611+
of ``my_method``.
612+
613+
To learn more about ``Callable``, check out the class reference here: :ref:`Callable <class_Callable>`.
603614

604615
Having your object sending out signals is more common. For our wobbling
605616
Godot icon, we'll do something silly just to show how it works. We're going to

0 commit comments

Comments
 (0)