#How to emit signal in parent and receive to run function in child?

1 messages · Page 1 of 1 (latest)

mellow bay
#

For a tower defense game: the RedTower object shoots at enemies, and UpgradeWidget is something that is dropped by enemies, and can be added/removed during gameplay. Since the upgrade is a modular sort of the form [Conditional Trigger] [Effect] [Magnitude], I want to have the Towers emit signals and the upgrades receive them. Since the upgrades, and therefore child nodes, aren't guaranteed to be there, I don't think I can safely call methods. The best idea I can come up with is to create all signals in the Tower and connect the appropriate signal to the child's function with a match case when the child is added(and conversely, disconnect it when the child is removed). In theory, this should work since all nodes are in the same scene at runtime? However, the closest I've been able to come is linking the child node's function to its own signal, rather than the signal of the parent function, even though the signal shares a name in both scenes. I have thus far been unsuccessful in finding either an answer or someone who has attempted this before me, either on google or in the signal documentation.

Help?

#

should note: parent and child start in separate scenes, in case that makes setup messy

unkempt falcon
#

If it's the receiving end connecting:
SendingNode.connect("signal", function)
If it's the Sender that is connecting
connect("signal", ReceivingNode.function)
If it's a third node managing the two:
SendingNode.connect("signal", ReceivingNode.function)

mellow bay
unkempt falcon
#

Oh you also have the other method of:
Node.signal.connect(ReceivingNode.function)