rabcor
1
Godot Version
4.3
Question
I’ve tried following tutorials and the documentation on how to use connect() to connect signals via code, however it just does not seem to work.
From Using signals — Godot Engine (stable) documentation in English :
timer.timeout.connect(_on_timer_timeout)
Won’t work because there are too few arguments.
And what I usually see in tutorials.
$Something.connect("signalname",self)
Doesn’t work because ‘self’ as a relative path to the current script is not callable.
How do I use this function? To, say, connect a child to a parent’s signal?
KingGD
2
the first one is correct, but not sure why it won`t worked, can you show a screenshot of the error?
rabcor
3
The error was that connect() requires a minimum of 2 arguments.
I’ve figured this out though.
get_parent().connect("signal",_on_node_2d_signal)
func _on_node_2d_signal() -> void:
I just needed to create a callable function to use instead of ‘self’. Not sure how it works if i’m connecting from the parent to the child though.
3 Likes
Sanne
4
For completeness - you can use either syntax, both are correct. Both Object class and Signal class have a connect method.
So you can use:
my_object.connect("my_signal", my_callable)
or (since Godot 4.0):
my_object.my_signal.connect(my_callable)
1 Like
system
Closed
5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.