Best use cases for observer pattern messenger system

I’m looking at implementing an observer pattern messenger/event system in my game, something like the Notification Center on the wiki, but I find myself confused when deciding what are the best use cases for it.

I can totally see something like, an “NPC Death” event being a great use case, because you’d want your effects manager to create some particle effects there, or your score manager to increment the player’s score, stuff like that.

But what about an “NPC Take Damage” event? It makes sense that something like an effects manager would want to subscribe to such an event, to make some blood particles or something, but should every NPC subscribe to it? If they did, the NPC who took the hit would have to be passed with the event, and then every enemy would have to check if it was him, right? That seems like a lot of CPU cycles, as opposed to calling the “Take Damage” function on the enemy being hit directly, via either SendMessage or a GetComponent() direct function call, no?

Cross-post: http://answers.unity3d.com/questions/613584/best-use-cases-for-an-observer-pattern-messenger-s.html

From my point of view, taking damage should be direct and probably involving some interface. Not everybody want to test if they did receive some damage. It makes no sense to broadcast that to everybody.

Events, again for me, should be use when you don’t know who is listening or would want that info. Even your NPC Death is not such a good example, because scoring should be direct to the singleton handling that, and the NPC should handle spawning FX itself with direct communication with whatever FX manager you have.

NPC Death becomes more useful if the NPC is part of a squad and other AI change their behaviour or if there’s other NPC around needs that info to flee. Imagine shooting a NPC in a crowd, other NPC need to look at the dead body and react. In this case, generic broadcasting makes sense. On top, not everything register that to event, only script that needs it.