Version: 2019.2
Creating jobs
JobHandle and dependencies

Scheduling jobs

To schedule a job in the main thread, you must:

  • Instantiate the job.
  • Populate the job’s data.
  • Call the Schedule method.

Calling Schedule puts the job into the job queue for execution at the appropriate time. Once scheduled, you cannot interrupt a job.

Note: You can only call Schedule from the main thread.

An example of scheduling a job

// Create a native array of a single float to store the result. This example waits for the job to complete for illustration purposes
NativeArray<float> result = new NativeArray<float>(1, Allocator.TempJob);

// Set up the job data
MyJob jobData = new MyJob();
jobData.a = 10;
jobData.b = 10;
jobData.result = result;

// Schedule the job
JobHandle handle = jobData.Schedule();

// Wait for the job to complete
handle.Complete();

// All copies of the NativeArray point to the same memory, you can access the result in "your" copy of the NativeArray
float aPlusB = result[0];

// Free the memory allocated by the result array
result.Dispose();

  • 2018–06–15 Page published

  • C# Job System exposed in 2018.1 NewIn20181

Did you find this page useful? Please give it a rating:

Creating jobs
JobHandle and dependencies