How to despawn entities safely¶ Despawn immediately when not iterating: 1world.despawn(e); Despawn during a query/system via cmd(): 1 2 3 4 5 6 7 8world.addSystem((w: any) => { for (const { e, c1: pos } of w.query(Position)) { if (pos.x > 10) w.cmd().despawn(e); } }); // apply despawns world.flush(); Or rely on end-of-frame flush: 1world.update(dt); // runs systems, then flushes