Two punches at once. The same fight in Bevy ECS and Flecs
I coded the same duel in Rust and C. Two engines, two ways to pick a target, and one rule that decides whether the last punch lands in time.

Machine translation. Read the original in Español
In this article
A and B hit each other at the same time. Both have just enough health left to go down. If the one you created first in code wins, you have a pretty rigged fight.
I wanted both of them to hit the floor. I wrote the same turn twice: in Rust with Bevy ECS 0.20.1, without loading the graphics engine, and in C11 with Flecs 4.2.0. The two implementations fit in a console. The ZIP includes the pinned versions, instructions, and outputs.
The turn that exposes the bug
A starts with 18 health, hits for 12, and absorbs 2. B has 24 health, hits for 8, and absorbs 4. After subtracting the defender's defense, A loses 6 per turn. B loses 8.
| At the end | A's health | B's health | Punches thrown |
|---|---|---|---|
| Turn 1 | 12 | 16 | 2 |
| Turn 2 | 6 | 8 | 2 |
| Turn 3 | 0 | 0 | 2 |
| Turn 4 | 0 | 0 | 0 |
At the start of the third, both are still standing. If I subtract B's health when resolving A's punch and then ask B if it can attack, I've already stolen its turn. I split it into two passes. Each living attacker pushes its target and hit power onto a queue. Only once all of them are in do I apply the damage. That way B can take its final punch with its own already on the way.
Where the rule is written in Bevy
I made health, power, and defense three components. The relationship AimsAt points to the opponent. At the other end, TargetedBy gathers everyone targeting it. Bevy updates that side when I insert the relationship.
The system collect reads the attackers and writes to the queue. apply reads the queue and modifies the defenders' health. If I revisited this code in six months, I would look for this line.
schedule.add_systems((collect, apply).chain());
The scheduler knows that two incompatible accesses have to take turns. What it cannot know is which of the two goes first in my game. That is what I write down with chain().
In Flecs I can ask who is targeting B
In C I registered the same three components and gave AimsAt the trait Exclusive. Each attacker thus has a single target for that relationship. To aim A at B I added the pair (AimsAt, B). The query asks for health, power, and any pair starting with AimsAt.
desc.terms[2].id = ecs_pair(AimsAt, EcsWildcard);
While iterating over the results, the third term holds the concrete pair that matched. With ecs_pair_second I extract the target and put it in the queue. Once the query finishes, I apply the damage. I could build both phases with Flecs systems. For this duel, they fit one right after the other in C.
The difference that interests me most shows up the day B wants to know who is targeting it. In Flecs I can replace the wildcard with B and query that pair. In Bevy, B already has its attackers gathered in the reverse collection.
The test I'd still want to run
In each version I created A first, then repeated the duel creating B first. The assertions check health and the number of hits on each turn. Four identical results, including the empty fourth turn.
If the game is already in Rust and depends on the order of its systems, I would start with Bevy ECS. If I had a C simulation with lots of links I need to query, I would start with Flecs. And if I'm worried about what it costs to change thousands of targets per frame, I'll have to build that benchmark. Here, what I wanted to know was whether B managed to throw its punch. It does.