I currently have an entity component system with messaging. The messages are delivered to each subscriber, but each subscriber gets their own copy, basically meaning that altering a message doesn't affect any other subscriber. While this works fine for now, I was wondering how I would add an invulnerable state.

I have a combat system that solves combat. It takes a combat event (an intent to attack something) and emits a resolved combat event. This event contains information of who attacked whom and what kind of damage they took. It also has a bool which gives the status of whether or not the defending entity is alive after the attack. It also controls the the HP and deletes the entity if it was killed.

I do not have a problem breaking down this system. A system that calculates damage, a system that applies the damage, and a system that kills the entity. But where do I add my invulnerability? If I simply make it a component, then it has to be handled by the system that applies damage. What if I want to add something else later? I have to build up and up the damage system and it has to handle all the little edge cases and intricacies. What if I want to add an attack that goes through invulnerability?

Clearly this is an exponential nightmare, which is exactly what I hoped to avoid with an ECS. How should I handle invulnerability?

  • \$\begingroup\$ What about switching from a plain messaging system to a event-system, where subscribers can either approve or decline the event to happen? This would also fit in other parts of the componentsystem, for example, your input-system would send a move-event but your physics-system would then decline it or even change the outcome because there is a wall in front of you. \$\endgroup\$
    – tkausl
    Commented Jul 26, 2015 at 21:41
  • \$\begingroup\$ Sorry, I might have not made it clear that it is an event system. I don't quite understand what you mean by decline an event, although this seems like an interesting approach. Lets say my input system dispatches a move event, which my physics system picks up. If I collide due to this move, how would my physics system tell my input? \$\endgroup\$
    – user975989
    Commented Jul 26, 2015 at 21:45
  • \$\begingroup\$ It wouldn't directly, it would not even care from where the move came, all it would care is that someone wants to move in a wall and thats not possible. You'd probably need a flag inside the eventclass or even subclass Event to an DeclinableEvent or CancelableEvent or even allow subscribers to alter things. This would mean that the input-system creates a move-event which contains the new coordinates, the physics-event may alter those coordinates or cancel the event and after calling all subscribers you had to update the entities position based on the outcome of the event. \$\endgroup\$
    – tkausl
    Commented Jul 26, 2015 at 21:56
  • 1
    \$\begingroup\$ In case of your invulnerability you may have a buff where the buff-system subscribes to the event-system and just cancels damage-events at all or a 50% more armor buff may only change the damage-value inside the event. \$\endgroup\$
    – tkausl
    Commented Jul 26, 2015 at 21:59

1 Answer 1


ECS doesn't make miracles and not all the problems should be solved by it. In some point you will need especific code about the specific logic of your game.

You can put an "Invulnerable" flag inside your health component and a flag "PenetrateInvulnerability" inside the atack message and your system combat manage then.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .