I am most definitely using the entity command system completely wrong and I need some clarifications
My ISystem OnUpdate looks like this
EntityCommandBufferSystem ECBSystem = state.World.GetOrCreateSystemManaged<EndSimulationEntityCommandBufferSystem>();
EntityCommandBuffer ECB = ECBSystem.CreateCommandBuffer();
EntityCommandBuffer.ParallelWriter ECBParallel = ECB.AsParallelWriter();
EntityCommandBufferSystem
I'm not completely sure what this does, all ik is that you can create command buffers and you can add a job handle for jobs that includeEntityCommandBufferSystem.ParallelWriterwith
ECBSystem.AddJobHandleForProducer(handle);. Other than that I'm pretty lost.
EntityCommandBuffer
This is basically a list of commands that the entity manager needs to do, instead of doing each one every time, it'll only do them at certain times. Also, it requires.Playback(EntityManager)in order to actual queue changes, I think that's how it works?
EntityCommandBuffer.ParallelWriter
This is supposedly only used withinIJobParallelForto safely write into theEntityCommandBufferI'm not exactly sure why I need to:
ECBSystem.AddJobHandleForProducer(handle);
state.Dependency = handle;
TL;DR
Now here's my problem:
I recognize that anyEntityCommandBufferyou make needs to be disposed. However, I useEntityCommandBuffer.ParallelWriterin aIJobParallelForand so when I try to disposeEntityCommandBufferit expectingly gives me an error that I cannot dispose something currently being read to. If I don't disposeEntityCommandBufferit'll be a memory leak
A possible solution is to basically force this job to complete within the same frame, but most of my other jobs are independent, and are not strict with completion times, so I wish the job to be completely parallel.
I've also considered using the "World" EntityCommandBuffer but I'm not sure how to gain access to it or how it differs from a normal buffer.