Version: 2019.2
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
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961