I’ve been messing with ECS again after a while and I have a long running task (it takes about 60% of the total frame time) and while that is being calculated it is possible for other systems that don’t have a dependency to run. I noticed a bug in the long running system which requires me to wait for the job to finish and directly assign a component value to an Entity. As far as I can tell I have to wait for the handle to complete then set the value like this:
MainJob job = new MainJob();
JobHandle jobHandle = job.Schedule(Dependency);
//Super slow, but unavoidable?
jobHandle.Complete();
// Have to wait in order to get access to the complete content of the result
EntityManager.SetComponentData(m_entity, new JobResultData{FrameResult = job.Result});
Is there some trick to setting the component data automatically with a jobHandle so that other Systems can run as this one is finishing up? Maybe something like this where the dependency is passed directly into the component set (yes, this isn’t an API atm but one can dream):
MainJob job = new MainJob();
Dependency = job.Schedule(Dependency);
// Allow system update to finish and start down stream systems immediately without blocking
EntityManager.SetComponentData(m_entity, new JobResultData{FrameResult = job.Result}, Dependency);
I know that this might not be ideal because I have to create a new IComponent instance but if there is some way to do this I can just do the creation as part of the job. This would allow other threads to have work queued up as this job isn’t parallel-able.