Signal received on next frame instead of a current one

Godot Version

4.3

Question

Hello, I’m making my first project where I have multiple copies of a node emitting the same signal to a single parent node, e.g.:
each 4th frame children emit “hit” signals with “target” and “damage” as arguments;
each 4th frame parent calls queue_free() on child if it has no hp

The problem is: parent receives some of the signals at FRAME+1 (no such signals are emitted at this frame) and tries to address an already dead node (it was already hit at FRAME+0 by someone else)

Is it expected behavior? What would be a correct approach here?

Thank you

Depending on what you are trying to do there would be different work arounds for this. Could you explain you node hierarchy and your code further?

One work around would be to check for queue_free()-ing every time the parent node receives the hit-signal.

1 Like

Currently I have a parent node, let’s call it NPCs, and child CharacterBody2D e.g. NPC, which multiplies itself and can attack it siblings:

  • NPCs
    • CharacterBody2D
  • signal_manager

It means that each sibling that is being created can send ‘hit’ signal

emit_signal("hit", self, map.tiles[target_pos].occupant, 5.0)

image
The problem is, in my plan, “signal_manager” node should call change_hp for the target at the same frame the signal was emmited, but as I can see (the signals probably don’t work this way) some of the emitted hits with a same target (in a single frame) can invoke “change_hp” at the next frame

I am not sure if I can really help you with that. This reddit post informs about signal connections further and might help you:
https://www.reddit.com/r/godot/s/sKGs7uCCID

1 Like