Version: 2019.4
NativeContainer
Scheduling jobs

Creating jobs

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:

  • Create a struct that implements IJob.
  • Add the member variables that the job uses (either blittable types or NativeContainer types).
  • Create a method in your struct called Execute with the implementation of the job inside it.

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 main thread is by writing to a NativeContainer.

An example of a simple job definition

// 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

NativeContainer
Scheduling jobs