Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Feature Request Add methods to add several Transforms to a TransformAccessArray

Discussion in 'C# Job System' started by Enderlook, Mar 2, 2023.

  1. Enderlook


    Dec 4, 2018
    The following type contains a constructor with the signature:
    Code (CSharp):
    1. public TransformAccessArray(Transform[] transforms, int desiredJobCount);
    I propose adding the overloads to the constructor:
    Code (CSharp):
    1. public TransformAccessArray(ReadOnlySpan<Transform> transforms, int desiredJobCount);
    2. public TransformAccessArray(List<Transform> transforms, int desiredJobCount);
    And the following overloads to the method:
    Code (CSharp):
    1. public void SetTransforms(ReadOnlySpan<Transform> transforms);
    2. public void SetTransforms(List<Transform> transforms);
    And the new method:
    Code (CSharp):
    1. public void AddRange(Transform[] transforms);
    2. public void AddRange(ReadOnlySpan<Transform> transforms);
    3. public void AddRange(List<Transform> transforms);
    Alternatively, adding overloads that accept count would also be useful such as:
    Code (CSharp):
    1. public void SetTransforms(Transform[] transforms, int count)
    So you can specify how many items you want to set.

    This would make it easier to construct TransformAccessArray with populated results.
    Of course, you can right now emulate them by iterating the collection and using the Add method, or creating a new array with the specific size, but that is more expensive due to potential allocations, safety checks, and/or internal calls.

    Having that additional overloads would make stuff easier and more performant, and they are trivial to implement.
    Qriva and Haxel0rd like this.
  2. Qriva


    Jun 30, 2019
    I still don't understand why literally everything related to job system have overloads for everything, meanwhile TransformAccessArray content manipulation is so poor and mysterious.