I think like many, you get reasonably far with building components and systems; that you get to a point where you have to destroy something. That’s when the real learning starts IMO. I’m hoping the ECS team comes up with a way to streamline this. DestroyEntity appears easy to use, but as many forum posts attest to - this is not the case.
So having gone through the ‘how and which command buffer do I delete my entities so I don’t have bizarre systems behavior’ debacle… I find myself adding .WithNone(typeof(<destroycomponenttag>) on almost everything. It’s the only way I’ve found to filter out entities that are pending real destruction
Is this the typical / expected pattern that you need to adopt beyond a simple demo? If not, can someone offer advice so I can correct my patterns? Thanks.
Simplest thing that other people have come up with has come up is to create another ecb system that runs after EndSimulationEntityCommandBufferSystem and only ever destroys entities. That way any changes that occur in endsim never conflict with any missing entities.
That’s the same approach.
If you never write to a command buffer that is played back before the system using it ( which would push the command to the next frame) and always only destroy your entities in the first buffer of the frame, there should be no way for a conflict to happen.
Ok, so to recap, I should not have to add .WithNone(...) everywhere - is what I’m hearing.
I guess I’m still doing something wrong… most of my ISystem’s in the main simulation update are writing to the same command buffer. So, you’re saying those don’t actually happen till the next frame.
I guess I’m unsure as to which command buffer my ISystem’s should be using… if not BeginSimulationEntityCommandBufferSystem, then what?
If you have an Isystem in the simulation group write to the begin simulation command buffer, then that command will be executed on the next frame when that buffer is played back.
Since the begin simulation play back has already happened for the current frame.
But if you write the command to the end simulation buffer it will be played back in the current frame when that buffer is played back.