#signals

4 messages · Page 1 of 1 (latest)

vagrant hinge
#

i got a little question about signals here
is there a way i can connect signals dynamically?
because, i want one of my controls to emit a custom signal that gets picked up by a node wich just gets added as its parent later...is that possible or do i need to find another solution to this

i already got the signal emitted in the control node and i theoretically got the function that should listen to it in the node above...the signal gets emitted, but the parent node dont seem to listen to it

here are the two lines in the control node called "selection_menu":


[....]

emit_signal("create_new_menu","load")```

and here from the function that should listen to it:

```func _on_selection_menu_create_new_menu(to):```

Thank you for your help :)
shut karma
#

yeah just writing the function doesn't actually make it listen, you gotta use connect to set that up like the docs link above shows

urban hazel
#

@vagrant hinge Each Object has a function called "connect" (ref. https://docs.godotengine.org/en/stable/classes/class_object.html#class-object-method-connect). It is used to connect to signal.

E.g.:


func _ready():
    node_with_signal_defined.connect("create_new_menu", self, "_on_create_menu")

func _on_create_menu(param: String) -> void:
    print("Got parameter: ", param) # prints 'load'

You can also be interested in "event bus" or "observer pattern" which greatly simplifies signalling between nodes which are "far away" from each other inside tree:
https://www.gdquest.com/docs/guidelines/best-practices/godot-gdscript/event-bus/

I'm using event bus all the time, personally. Cheers.

GDQuest

This guide covers some best practices to write solid GDScript code, to keep a sane code-base when developing projects of growing sizes.