Signal emission not being recieved by node (await)

Godot Version

4.2.1.stable.official

Question

I have two nodes communicating through each other by emitting and awaiting signals like so:

Node1.gd

signal signal1
%Node2.signal2.emit(data)
var response = await signal1

Node2.gd

signal signal2
var response = await signal2
%Node1.signal1.emit(data)

Node2 successfully recieves signal2 as emitted by Node1. But when Node2 emits signal1 to Node1, it never recieves anything.

%Node1.signal1.emit(data) is run, as any code placed after the line runs as expected. But Node1 is left awaiting for signal1 forever. I can also access other Node1 properties from within Node2 by using %Node1, so the unique identifier seems to be working.

Is there something about either signals or await I’m misunderstanding here? I can’t quite wrap my head around why this is happening.

Solved – after doing some research I found out that emit_signal blocks the execution of subsequent code until all of the code the signal is connected to finishes executing.

My Node2 code was being run in a loop that relied on user input to iterate over, so it never ‘finished’ executing per se.

To prevent this I had to defer the signal emission. In place of %Node2.signal2.emit(data), I used this lambda function:
(func(): %Node2.signal2.emit(data)).call_deferred()

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.