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
- Type: Interface
- Namespace: UnityEngine.Jobs
- Assembly: UnityEngine.CoreModule
[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:
- IJobParallelForTransformExtensions.RunReadOnlyByRef runs the job on the main thread and finishes immediately, with read-only access to the transform data.
- IJobParallelForTransformExtensions.ScheduleReadOnlyByRef schedules the job to run asynchronously, distributing the work across multiple worker threads. This scheduling option can give the best performance, but race conditions can occur if the job writes to shared or global data without proper synchronization.
- IJobForExtensions.ScheduleByRef is the same as above, but the job has read/write access to the transform data.
Execute(int index, TransformAccess transform)RunReadOnlyByRefExecute(int index, TransformAccess transform)ScheduleReadOnlyByRefScheduleByRefExecuteEach 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 to check that the job has completed, or pass it to other jobs as a dependency. When you pass a as a dependency, it ensures that the jobs are executed one after another on the worker threads.
JobHandleJobHandleAdditional Resources: IJobParallelForTransformExtensions.
Examples
{code Tests/EditModeAndPlayModeTests/Jobs/Assets/DocumentationExamples/TransformJobDocExamples.cs#ijobparallelfortransform-apidocs-example}
Methods
Method | Description |
|---|---|
| Execute | Performs work against a specific iteration index and transform. |