I’m struggling quite a lot to destroy a very specific entity, every example I tried so far seems to nuke every entity of that specific type, how can I get EntityCommandBuffer to only destroy the given one with the given condition?
foreach (var (bodyCollisionTag, entity) in SystemAPI.Query<RefRW<BodyCollisionTag>>().WithEntityAccess())
{
if (bodyCollisionTag.ValueRO.sufferedDeadlyCollision)
{
var ecb = new EntityCommandBuffer(Allocator.Temp);
ecb.DestroyEntity(entity);
}
}
The posted code won’t do anything, the ECB is not played back anywhere. Look at the documentation for manual playback or the singletons. Use DestroyEntity as you are doing there, and it will destroy every entity where your condition is true. If more or less entities are destroyed than you’re expecting, there’s some other flaw in how the condition gets its value that you need to figure out.
that works perfectly fine now, it had to be me doing something stupid, thanks for this and everything else, I’ve been reading a lot of your answers to fix a lot of problems over the last month