docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Interface IJobParallelForDefer

    Calculates the number of iterations to perform in a job that must execute before an IJobParallelForDefer job.

    Namespace: Unity.Jobs
    Assembly: Unity.Collections.dll
    Syntax
    [JobProducerType(typeof(IJobParallelForDeferExtensions.JobParallelForDeferProducer<>))]
    public interface IJobParallelForDefer
    Remarks

    A replacement for IJobParallelFor when the number of work items is not known at Schedule time.

    When Scheduling the job's Execute(int index) method will be invoked on multiple worker threads in parallel to each other.

    Execute(int index) will be executed once for each index from 0 to the provided length. 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.

    Unity automatically splits the work into chunks of no less than the provided batchSize, and schedules an appropriate number of jobs based on the number of worker threads, the length of the array and the batch size.

    Choose a batch size sbased on the amount of work performed in the job. A simple job, for example adding a couple of float3 to each other could have a batch size of 32 to 128. However, if the work performed is very expensive then it's best to use a small batch size, such as a batch size of 1. IJobParallelFor performs work stealing using atomic operations. Batch sizes can be small but they aren't free.

    The returned JobHandle can be used to ensure that the job has completed. Or it can be passed to other jobs as a dependency, ensuring that the jobs are executed one after another on the worker threads.

    Methods

    Execute(int)

    Implement this method to perform work against a specific iteration index.

    Declaration
    void Execute(int index)
    Parameters
    Type Name Description
    int index

    The index of the Parallel for loop at which to perform work.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)