#When nodes are not structurally next to each other, how should they communicate without coupling?

3 messages · Page 1 of 1 (latest)

placid jetty
#

I think the answer is "Use signals" but I don't understand how.

Goal: When a Mob dies, I want a Coin to appear in it's place.

As shown in the diagram, every mob lives under a Mob Manager node. When the Health Component hits zero, a signal is emitted from it which the Mob listens to. The Mob plays a death animation. Once that is complete, I want a coin to appear where the Mob was. However, I don't understand how to properly set this up.

Noisy Solution - Listen and rebroadcast signals all the way to the Level

This feels very cumbersome, but I could have the Mob emit a signal when it finishes dying which the Mob Manager listens to. The Mob Manager could emit a signal that the Level listens to. The Level has a Coin Manager, so it could directly call the Add_Coin function.

Ideal Solution - The Mob talks, the Coin Manager listens

I could have the Mob emit a signal when it finishes dying which the Coin Manager listens to. The Coin Manager handles creating the Coin. This feels like the correct solution, but I don't understand how to code it without introducing a coupling between a Mob and a Coin Manager. Where and how do I wire up the connection from a Mob to the Coin Manager? I don't see how one could know about the other. Mobs are instantiated in script, so the signal needs to be scripted as well.

#

Better diagram. Sorry.

valid lagoon
#

At some level, Mobs (and probably Mod Managers) have to be created by the level. When the level first instantiates them, it can connect signals from the new nodes to the coin manager, and then forget about it and leave the signals to do their work.