Hello,
So I have following scenario:
I have a native array defined and initialized in main code. Something like:
public NativeArray<int> myArray;
Then I have 2 jobs defined, something like:
public struct MyJob : IJob
{
[ReadOnly] public NativeArray<int> data;
public NativeArray<int> result;
...
}
I’m calling them as follows:
var job1 = new MyJob()
{
data = myArray,
result = myResult1
};
job1.Schedule();
var job2 = new MyJob()
{
data = myArray,
result = myResult2
};
job2.Schedule();
Please note above code is just for reference.
I’m getting an error “The previously scheduled job … writes to the NativeArray data. You are trying to schedule a new job …, which writes to the same NativeArray”.
The question is how can I use same native array just for reading data in different jobs running in parallel? Is it allowed? Or, do I need to copy to a local array and pass it separately for each job? The manual stipulates that “The safety system does allow multiple jobs to read from the same data in parallel.”, but I cannot make it run for some reason.
I’m using Unity 2018.4.2f1
Thanks