Why not just write PlanetSizeComponent into NativeArray instead of writing fields data separately?
If next job only need to read results of previous job it’s a good way. I use NativeQueue for those tasks. If next job require RW random access, you can use ComponentDataFromEntity and just collect all Entities in first job.
public class DeferredSystem : JobComponentSystem
{
private struct FillJob : IJob
{
public int Count;
public NativeList<int> ListToFill;
public void Execute()
{
for (int i = 0; i < Count; i++)
{
ListToFill.Add(i);
}
}
}
private struct DeferredJob : IJobParallelForDefer
{
[ReadOnly] public NativeArray<int> DeferredList; //Read only just for example
public void Execute(int index)
{
var value = DeferredList[index];
}
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var deferredList = new NativeList<int>(Allocator.TempJob);
inputDeps = new FillJob()
{
Count = Random.Range(1, 99),
ListToFill = deferredList
}.Schedule(inputDeps);
return new DeferredJob()
{
DeferredList = deferredList.AsDeferredJobArray()
}.Schedule(deferredList, 32, inputDeps);
}
}
Thank you, I was getting stuck on getting my EntityQuery to a NativeList. Was hoping for something similar to EntityQuery.ToComponentDataArray but for NativeList (or IbufferComponent to NativeList)
So if noting like this exist do I need another job to pass from a component array to a nativeList ?
Depend on case. If you using EQ and know buffer before schedule, why you need that? Why just not get buffer in OnUpdate and schedule job with this buffer length? Explain your case a bit more detailed IJobParallelForDefer needed if you don’t know data length at scheduling time (for example previous job accumulate some data array under certain conditions), but in your case (I relates on your OP code) you have data already, you know it length (you can get data arrays, buffers etc fro EQ), you not changing this data and ranges in previous job.