#How can I do nested iteration of entities in jobs?
1 messages · Page 1 of 1 (latest)
run additional job before which will store all entities in a suitable way
and then use that collection in your main job
How can I know then how may entities matches the query?
i.e:
partial struct CollectJob : IJobEntity
{
[WriteOnly] NativeArray<(X, Y)> array; // How much space should I allocate?
void Execute([EntityIndexInQuery] int i, in X x, in Y) => array[i] = (x, y);
}
_query.CalculateEntityCount()
Oh, thanks!
This may not be directly relevant here, but if you have a case where Job1 is generating a variable-size list of elements and Job2 is going to iterate over that list of elements, and you want to avoid the sync between after Job1 where you compute how many elements it wrote and pass that count to Job2, you may want to look into IJobParallelForDefer
(or NativeList.AsDeferredJobArray())