So it’s generally best practice to leave entity destruction up to a single system (usually the decay). This is good because you can easily have systems that last for a specific amount of time for basically free (fire dealing damage over time is a good example). The problem I am currently running into is systems that must work for exactly 1 frame. Before I took for granted that I could destroy these entities in their respective systems but that eliminates the ability to easily add things like the above damage over time example.
My problem is when a projectile impacts a collider with a health component, the projectile will create a new entity with an attack component, and a decay component with a lifetime of 0.
My decay state simply detects when new decays come into existance, adds them to a map with their id and their expected lifetime, and subtracts the current tpf from their lifetime every frame. Once their life is <= 0 they are destroyed.
Because my decay state is so universal I typically add it first, but this causes a problem: my lifetime 0 entities are killed at the very beginning of the frame, before other systems have a chance to see them. If I carefully lay out the order of my systems I can sort of work around this, but now system order is extremely important, and I am starting to lose the benefits of the ecs. If I delay the decay from acting for 1 frame I still need to very carefully lay out the system order or some systems may act on the same entity twice.
What’s the best practice for implementing systems that need to work exactly once? Should I ignore the ecs for these systems? Should the attack system be evolved to track a total amount of damage per attack, and a max damage per frame to ensure the entire attack is accounted for? The last one sounds appealing but it also means I won’t be using the simpler decay method for persitant damage.