Im having trouble writing to a Native array using IJobParallelFor.
So here is my attempt and I can see this will never work because as I understand it the WriteArray is “Sliced” across multiple threads. So how do I loop over my WriteArray ?
IndexOutOfRangeException: Index 0 is out of restricted IJobParallelFor range [8…10] in ReadWriteBuffer.
[BurstCompile]
struct Test : IJobParallelFor
{
[WriteOnly]
public NativeArray<Vector3> WriteArray;
[DeallocateOnJobCompletion]
public NativeArray<ArchetypeChunk> Chunks;
[ReadOnly]
public ArchetypeChunkComponentType<PosComponent> PositionArchetype;
public void Execute(int chunkIndex)
{
var chunk = Chunks[chunkIndex];
var chunkPos = chunk.GetNativeArray(PositionArchetype);
var instanceCount = chunk.Count;
for (int i = 0; i < instanceCount; i++) // this wont work
{
WriteArray[i] = new Vector3(chunkPos[i].Position.x, chunkPos[i].Position.y, chunkPos[i].Position.z);
}
}
}
Any help would be appreciated