docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class IJobParallelForBatchExtensions

    Extension class for the IJobParallelForBatch job type providing custom overloads for scheduling and running.

    Inheritance
    object
    IJobParallelForBatchExtensions
    Namespace: Unity.Jobs
    Assembly: Unity.Collections.dll
    Syntax
    public static class IJobParallelForBatchExtensions

    Methods

    EarlyJobInit<T>()

    Gathers and caches reflection data for the internal job system's managed bindings. Unity is responsible for calling this method - don't call it yourself.

    Declaration
    public static void EarlyJobInit<T>() where T : struct, IJobParallelForBatch
    Type Parameters
    Name Description
    T
    Remarks

    When the Jobs package is included in the project, Unity generates code to call EarlyJobInit at startup. This allows Burst compiled code to schedule jobs because the reflection part of initialization, which is not compatible with burst compiler constraints, has already happened in EarlyJobInit.

    Note: While the Jobs package code generator handles this automatically for all closed job types, you must register those with generic arguments (like IJobParallelForBatch&lt;MyJobType&lt;T&gt;&gt;) manually for each specialization with [[Unity.Jobs.RegisterGenericJobTypeAttribute]].

    RunBatchByRef<T>(ref T, int)

    Executes the parallel batch job but on the main thread. See IJobParallelForBatchExtensions.ScheduleBatch for more information on how appending is performed.

    Declaration
    public static void RunBatchByRef<T>(this ref T jobData, int arrayLength) where T : struct, IJobParallelForBatch
    Parameters
    Type Name Description
    T jobData

    The job and data to schedule. In this variant, the jobData is passed by reference, which may be necessary for unusually large job structs.

    int arrayLength

    Total number of elements to consider when batching.

    Type Parameters
    Name Description
    T

    Job type

    RunBatch<T>(T, int)

    Executes the parallel batch job but on the main thread. See IJobParallelForBatchExtensions.ScheduleBatch for more information on how appending is performed.

    Declaration
    public static void RunBatch<T>(this T jobData, int arrayLength) where T : struct, IJobParallelForBatch
    Parameters
    Type Name Description
    T jobData

    The job and data to schedule.

    int arrayLength

    Total number of elements to consider when batching.

    Type Parameters
    Name Description
    T

    Job type

    Remarks

    Unlike ScheduleBatch, since the job is running on the main thread no parallelization occurs and thus no indicesPerJobCount batch size is required to be specified.

    RunByRef<T>(ref T, int, int)

    Executes the parallel batch job but on the main thread. See IJobParallelForBatchExtensions.Schedule for more information on how appending is performed.

    Declaration
    public static void RunByRef<T>(this ref T jobData, int arrayLength, int indicesPerJobCount) where T : struct, IJobParallelForBatch
    Parameters
    Type Name Description
    T jobData

    The job and data to schedule. In this variant, the jobData is passed by reference, which may be necessary for unusually large job structs.

    int arrayLength

    Total number of elements to consider when batching.

    int indicesPerJobCount

    Number of elements to consider in a single parallel batch. This argument is ignored when using .RunByRef()

    Type Parameters
    Name Description
    T

    Job type

    Run<T>(T, int, int)

    Executes the parallel batch job but on the main thread. See IJobParallelForBatchExtensions.Schedule for more information on how appending is performed.

    Declaration
    public static void Run<T>(this T jobData, int arrayLength, int indicesPerJobCount) where T : struct, IJobParallelForBatch
    Parameters
    Type Name Description
    T jobData

    The job and data to schedule.

    int arrayLength

    Total number of elements to consider when batching.

    int indicesPerJobCount

    Number of elements to consider in a single parallel batch. This argument is ignored when using .Run()

    Type Parameters
    Name Description
    T

    Job type

    Remarks

    Unlike Schedule, since the job is running on the main thread no parallelization occurs and thus no indicesPerJobCount batch size is required to be specified.

    ScheduleBatchByRef<T>(ref T, int, int, JobHandle)

    Schedules a job that will execute the parallel batch job for all arrayLength elements in batches of indicesPerJobCount. The Execute() method for Job T will be provided the start index and number of elements to safely operate on. In cases where indicesPerJobCount is not a multiple of arrayLength, the count provided to the Execute method of Job T will be smaller than the indicesPerJobCount specified here.

    Declaration
    public static JobHandle ScheduleBatchByRef<T>(this ref T jobData, int arrayLength, int indicesPerJobCount, JobHandle dependsOn = default) where T : struct, IJobParallelForBatch
    Parameters
    Type Name Description
    T jobData

    The job and data to schedule. In this variant, the jobData is passed by reference, which may be necessary for unusually large job structs.

    int arrayLength

    Total number of elements to consider when batching.

    int indicesPerJobCount

    Number of elements to consider in a single parallel batch.

    JobHandle dependsOn

    Dependencies are used to ensure that a job executes on workerthreads after the dependency has completed execution. Making sure that two jobs reading or writing to same data do not run in parallel.

    Returns
    Type Description
    JobHandle

    JobHandle The handle identifying the scheduled job. Can be used as a dependency for a later job or ensure completion on the main thread.

    Type Parameters
    Name Description
    T

    Job type

    ScheduleBatch<T>(T, int, int, JobHandle)

    Schedules a job that will execute the parallel batch job for all arrayLength elements in batches of indicesPerJobCount. The Execute() method for Job T will be provided the start index and number of elements to safely operate on. In cases where indicesPerJobCount is not a multiple of arrayLength, the count provided to the Execute method of Job T will be smaller than the indicesPerJobCount specified here.

    Declaration
    public static JobHandle ScheduleBatch<T>(this T jobData, int arrayLength, int indicesPerJobCount, JobHandle dependsOn = default) where T : struct, IJobParallelForBatch
    Parameters
    Type Name Description
    T jobData

    The job and data to schedule.

    int arrayLength

    Total number of elements to consider when batching.

    int indicesPerJobCount

    Number of elements to consider in a single parallel batch.

    JobHandle dependsOn

    Dependencies are used to ensure that a job executes on workerthreads after the dependency has completed execution. Making sure that two jobs reading or writing to same data do not run in parallel.

    Returns
    Type Description
    JobHandle

    JobHandle The handle identifying the scheduled job. Can be used as a dependency for a later job or ensure completion on the main thread.

    Type Parameters
    Name Description
    T

    Job type

    ScheduleByRef<T>(ref T, int, int, JobHandle)

    Schedules a job that will execute the parallel batch job for all arrayLength elements in batches of indicesPerJobCount. The Execute() method for Job T will be provided the start index and number of elements to safely operate on. In cases where indicesPerJobCount is not a multiple of arrayLength, the count provided to the Execute method of Job T will be smaller than the indicesPerJobCount specified here.

    Declaration
    public static JobHandle ScheduleByRef<T>(this ref T jobData, int arrayLength, int indicesPerJobCount, JobHandle dependsOn = default) where T : struct, IJobParallelForBatch
    Parameters
    Type Name Description
    T jobData

    The job and data to schedule. In this variant, the jobData is passed by reference, which may be necessary for unusually large job structs.

    int arrayLength

    Total number of elements to consider when batching.

    int indicesPerJobCount

    Number of elements to consider in a single parallel batch.

    JobHandle dependsOn

    Dependencies are used to ensure that a job executes on workerthreads after the dependency has completed execution. Making sure that two jobs reading or writing to same data do not run in parallel.

    Returns
    Type Description
    JobHandle

    JobHandle The handle identifying the scheduled job. Can be used as a dependency for a later job or ensure completion on the main thread.

    Type Parameters
    Name Description
    T

    Job type

    ScheduleParallelByRef<T>(ref T, int, int, JobHandle)

    Schedules a job that will execute the parallel batch job for all arrayLength elements in batches of indicesPerJobCount. The Execute() method for Job T will be provided the start index and number of elements to safely operate on. In cases where indicesPerJobCount is not a multiple of arrayLength, the count provided to the Execute method of Job T will be smaller than the indicesPerJobCount specified here.

    Declaration
    public static JobHandle ScheduleParallelByRef<T>(this ref T jobData, int arrayLength, int indicesPerJobCount, JobHandle dependsOn = default) where T : struct, IJobParallelForBatch
    Parameters
    Type Name Description
    T jobData

    The job and data to schedule. In this variant, the jobData is passed by reference, which may be necessary for unusually large job structs.

    int arrayLength

    Total number of elements to consider when batching.

    int indicesPerJobCount

    Number of elements to consider in a single parallel batch.

    JobHandle dependsOn

    Dependencies are used to ensure that a job executes on workerthreads after the dependency has completed execution. Making sure that two jobs reading or writing to same data do not run in parallel.

    Returns
    Type Description
    JobHandle

    JobHandle The handle identifying the scheduled job. Can be used as a dependency for a later job or ensure completion on the main thread.

    Type Parameters
    Name Description
    T

    Job type

    ScheduleParallel<T>(T, int, int, JobHandle)

    Schedules a job that will execute the parallel batch job for all arrayLength elements in batches of indicesPerJobCount. The Execute() method for Job T will be provided the start index and number of elements to safely operate on. In cases where indicesPerJobCount is not a multiple of arrayLength, the count provided to the Execute method of Job T will be smaller than the indicesPerJobCount specified here.

    Declaration
    public static JobHandle ScheduleParallel<T>(this T jobData, int arrayLength, int indicesPerJobCount, JobHandle dependsOn = default) where T : struct, IJobParallelForBatch
    Parameters
    Type Name Description
    T jobData

    The job and data to schedule.

    int arrayLength

    Total number of elements to consider when batching.

    int indicesPerJobCount

    Number of elements to consider in a single parallel batch.

    JobHandle dependsOn

    Dependencies are used to ensure that a job executes on workerthreads after the dependency has completed execution. Making sure that two jobs reading or writing to same data do not run in parallel.

    Returns
    Type Description
    JobHandle

    JobHandle The handle identifying the scheduled job. Can be used as a dependency for a later job or ensure completion on the main thread.

    Type Parameters
    Name Description
    T

    Job type

    Schedule<T>(T, int, int, JobHandle)

    Schedules a job that will execute the parallel batch job for all arrayLength elements in batches of indicesPerJobCount. The Execute() method for Job T will be provided the start index and number of elements to safely operate on. In cases where indicesPerJobCount is not a multiple of arrayLength, the count provided to the Execute method of Job T will be smaller than the indicesPerJobCount specified here.

    Declaration
    public static JobHandle Schedule<T>(this T jobData, int arrayLength, int indicesPerJobCount, JobHandle dependsOn = default) where T : struct, IJobParallelForBatch
    Parameters
    Type Name Description
    T jobData

    The job and data to schedule.

    int arrayLength

    Total number of elements to consider when batching.

    int indicesPerJobCount

    Number of elements to consider in a single parallel batch.

    JobHandle dependsOn

    Dependencies are used to ensure that a job executes on workerthreads after the dependency has completed execution. Making sure that two jobs reading or writing to same data do not run in parallel.

    Returns
    Type Description
    JobHandle

    JobHandle The handle identifying the scheduled job. Can be used as a dependency for a later job or ensure completion on the main thread.

    Type Parameters
    Name Description
    T

    Job type

    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)