Add/remove immediately when you are not iterating a query:
123456789
conste=world.spawn();world.add(e,Position,newPosition(0,0));world.add(e,Velocity,newVelocity(1,0));// Or add many at onceconstz=world.spawn();world.addMany(z,[newPosition(0,0),newVelocity(1,0)])world.remove(e,Velocity);
Add/remove during a query/system using deferred commands:
1 2 3 4 5 6 7 8 910111213141516
world.addSystem((w:any)=>{for(const{e,c1:pos}ofw.query(Position)){if(pos.x>10)w.cmd().add(e,Velocity,newVelocity(1,0));if(pos.x<0)w.cmd().remove(e,Velocity);}});// Or remove many at onceworld.addSystem((w:any)=>{for(const{e,c1:pos}ofw.query(Position,Velocity)){if(pos.x<0)w.cmd().removeMny(e,Position,Velocity);}});// apply queued structural changesworld.flush();