# Making more complicated systems(entity-component-system model question)

I'm using a model where entities are collections of components and components are just data. All the logic goes into systems which operate on components. Making basic systems(for Rendering and handling collision) was easy. But how do I do more compilcated systems? For example, in a CollisionSystem I can check if entity A collides with entity B. I have this code in CollisionSystem for checking if B damages A:

if(collides(a, b)) {
HealthComponent* hc = a->get<HealthComponent();
hc.reduceHealth(b->get<DamageComponent>()->getDamage());


But I feel that this code shouldn't belong to Collision system. Where should code like this be and which additional systems should I create to make this code generic?

## 1 Answer

Messaging is a common way of handling this. So your health system would subscribe to messages about collision, combat, etc. Then the health system is the only place where health is modified.

Messaging also allows multiple systems to subscribe to the same events. For example, when a collision happens the health system can be notified, sound system and the user notification system. Lots of options and it keeps code localized to the systems where it belongs.

See this question for some details about such systems.

• Is there any resources which show how to implement and use those systems? I think OP's solution was too difficult to understand with all those long named classes. Most tutorials I've seen focus only on the aspect of creating simple systems, but I've never seen one where messaging between systems is covered. – Elias Daler Oct 26 '13 at 18:34
• This site has a number of questions about it: gamedev.stackexchange.com/search?q=messaging+system+is%3Aq. Otherwise, you can ask a specific question about the trouble you're having implementing a messaging system if those questions don't solve your problems. – MichaelHouse Oct 26 '13 at 18:47
• I'll read this, thanks. My problem definitely will be solved using this. – Elias Daler Oct 26 '13 at 19:04
• By the way, which system do you use yourself? Any recommended approaches? Because most of the threads cover lots of themes to choose from. – Elias Daler Oct 26 '13 at 19:39
• I rolled my own. It'll probably be specific to your requirements. Start with something simple and keep adding the things you need. Any further discussion about it should be taken to chat. Good luck! – MichaelHouse Oct 26 '13 at 19:42