How does ZayES compare with Ashley?

So, just to make sure we are all on the same page. This discussion assumes you’ve read:

It seems like you probably have but I felt it should be explicit.

If I understand your issue then, it’s not how to add the damage entity when they enter the area but how to remove it when they’ve left. You have a few options here based on how scalable you want to be.

For a few hundred active AOEs… just keep a data structure in the system that is detecting when entities enter/exit the AOEs. A map of <aoe entityId + mob entityId, damage entityId> or whatever. Managing data structures inside the system like this is perfectly fine for most games that won’t run on giant server farms. When a mob leaves the area, look up its damage entity ID and remove it or decay it.

The purely scalable way would have some kind of CreatedBy component that is added to the damage entity and points back to the AOE. So when a mob leaves the AOE you look that up. It’s essentially the same processing you do in the last paragraph but less efficient. If your entities are basically in memory anyway then just use the easy way from above.

Note: an even better option that handles things like fire better would be to automatically put a decay component on any damage entity applied. Then while the mob is still in the AOE, just update the decay component on the damage entity. Now, you might say “but wait, isn’t that the same lookup as above but now I have to do it all the time?” Sort of… except you were already looping over all mob entities in the active AOEs. Now you wouldn’t have to do that anymore since you’d be iterating over the damage entities and checking to see if their target is still in an AOE. It’s effectively the same processing but now you’ve moved it to what you are actually managing: damage. It’s more “ES” and is precisely the kind of different way of looking at a problem that a data-oriented approach provides.