Why I can't immidetly connect the signal in the same function that signal emited?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By molesallegiance

So the problem is I want to connect signal of a child node to the parent node script.
But my code seems not working if I want to connect the signal like the code below.

So I have to go to the parent script node to connec it.

My question is why? Is it because .connect() function can’t see cross node? Like in this case || .connect(“level_selected”, self, “play_selected_level”) || the thid arguments || “play_selected_level” || must be found in the same script as .connect()?

Are you getting an error message or is the signal handler not being called? FYI: get_tree().call_group I beleive does a call_deffered of the given function, so that might be a source of you bug.

godot_dev_ | 2022-10-11 15:22

I only get these error. But it’s different case, because the error happen after the _on_select_level() get called again.

But no. Godot doesn’t register the connect function.

Ah… Wait… I must put connect signal in the _ready(). It cannot in the same function of the _on_select_level().

enter image description here

Yeah after a bit of looking up in the code. The problem seems to be what line being called first.

enter image description here

And it works… But it will give the error in the first image.

Hahaha even though it’s not related you point me to “signal handler not being called” made me realize my mistake though. Thanks.

molesallegiance | 2022-10-11 15:49

:bust_in_silhouette: Reply From: molesallegiance

Answer and reminder for future me or anyone who reads. The mistake seems to be which line being called first.

.connect() function in the image above is being called way after .emit_signal((). Basicly the signal already deliverd but the address is not in the same time as signal deliverd.

enter image description here

But the code above is not recomended, just put signal connect in the _ready() function.

enter image description here