To create a job in Unity you need to implement the IJob interface. IJob
allows you to schedule a single job that runs in parallel to any other jobs that are running.
Note: A “job” is a collective term in Unity for any struct that implements the IJob
interface.
To create a job, you need to:
IJob
.When executing the job, the Execute
method runs once on a single core.
Note: When designing your job, remember that they operate on copies of data, except in the case of NativeContainer
. So, the only way to access data from a job in the control thread is by writing to a NativeContainer
.
// Job adding two floating point values together
public struct MyJob : IJob
{
public float a;
public float b;
public NativeArray<float> result;
public void Execute()
{
result[0] = a + b;
}
}
2018–06–15 Page published
C# Job System exposed in 2018.1 NewIn20181