Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


IJobParallelForTransform

An interface that allows you to perform the same independent operation for each position, rotation and scale of all the transforms passed into a job.
Read time 2 minutesLast updated 13 days ago

Definition

[JobProducerType(typeof(IJobParallelForTransformExtensions.TransformParallelForLoopStruct<>))]public interface IJobParallelForTransform

Remarks

This job type is conceptually similar to IJobFor, but instead of iterating over a range of arbitrary data, it iterates over an array of transform data. Because Transform is a managed type and can't be safely manipulated by job code, this job type offers a workaround to that limitation.
Transform data is provided to the job in through TransformAccessArray, which wraps an array of Transform instances in an unmanaged TransformAccess type and allows the underlying data to be safely processed in parallel by worker threads.
This job type has the following options to schedule work:
Execute(int index, TransformAccess transform)
is executed once for each index from 0 to the provided length, with the corresponding transform data available through the provided parameter.
RunReadOnlyByRef
guarantees that the the job's
Execute(int index, TransformAccess transform)
method is invoked sequentially.
ScheduleReadOnlyByRef
and
ScheduleByRef
don't invoke the job's
Execute
method sequentially because it's called from multiple worker threads in parallel to each other.
Each iteration must be independent from other iterations and the safety system enforces this rule for you. The indices have no guaranteed order and are executed on multiple cores in parallel.
For jobs that request read/write access to transform data, Unity automatically splits and sorts the provided transform data into chunks that can be safely processed in parallel. All transforms from the same transform hierarchy will be processed by a single worker thread, to ensure that writing world-space transform data doesn't cause a race condition. However, the order in which transforms within a hierarchy are processed is not guaranteed.
You can use the returned
JobHandle
to check that the job has completed, or pass it to other jobs as a dependency. When you pass a
JobHandle
as a dependency, it ensures that the jobs are executed one after another on the worker threads.
Additional Resources: IJobParallelForTransformExtensions.

Examples

{code Tests/EditModeAndPlayModeTests/Jobs/Assets/DocumentationExamples/TransformJobDocExamples.cs#ijobparallelfortransform-apidocs-example}

Methods

Method

Description

ExecutePerforms work against a specific iteration index and transform.