Search Unity

Question IJobParallelForTransform - Batched?

Discussion in 'Entity Component System' started by Nirvan, Feb 27, 2023.

  1. Nirvan

    Nirvan

    Joined:
    Nov 16, 2013
    Posts:
    134
    Hello,

    I am using some batched IJobParallelForBatch jobs, which gives nice solution like:
    void Execute(int startIndex, int count)

    But I also want something like this for IJobParallelForTransform.
    I made NativeArray<int2> array which is passing start Index and count of the job correctly,
    but I want to do some calculations on all array elements of each batch except last one, and I need to call for loop every single Execute() call which produces unnecessary overhead.
    That's how it looks like:

    Code (CSharp):
    1.         public void Execute(int i, TransformAccess t)
    2.         {
    3.             t.position = procedPos[i];
    4.  
    5.             // Found out if it's first element in the batch array
    6.             // Dont call if it's last element on the array to avoid out of bounds exception with i+1
    7.             for (int b = 0; b < batchingRanges.Length; b++)
    8.             {
    9.                 if (i >= batchingRanges[b].x && i < batchingRanges[b].x + batchingRanges[b].y - 1)
    10.                 {
    11.                     t.rotation = rotForParent[i + 1];
    12.                     break;
    13.                 }
    14.             }
    15.         }
    Is there solution to call some job like IJobParallelForTransformBatch without loosing performance?
    I guess passing transforms to IJobParallelForBatch will be very slow if even possible.
     
    Last edited: Feb 27, 2023
  2. Nirvan

    Nirvan

    Joined:
    Nov 16, 2013
    Posts:
    134
    Thanks for the reply.
    I would like to and I was searching for a long time for interface like "IJobParallelForTransformBatched"
    but there is none to be found! Can't google it, can't find it in the docs.
    In which jobs api version I can get this interface? I just can't find any source for it.
     
    Michelle_Ca likes this.
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Why does this feels like a ChatGPT generated answer? Are we being invaded by rogue AI?
    There's IJobParallelForBatch though. Example - http://blog.s-schoener.com/2019-04-26-unity-job-zoo/#ijobparallelforbatch

    Unless someone's from the future, I don't think IJobParallelForTransformBatched exists.

    Back to the topic:
    As a suggestion - run a separate job before writing to the transforms.
    You can do pretty much anything outside of IJobParallelForTransform.

    Write values to temp location, read + combine it. Then apply results via IJobParallelForTransform.
    This should allow you to avoid touching transforms / managed part completely.
    And in theory should be faster as well.
     
    Spy-Master and Nirvan like this.
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    ... and that's why you shouldn't do that. Unless you're going to proofcheck every answer.

    ChatGPT isn't a reliable source of information. Moreover, it includes random noise to each answer by design. Meaning it "imagines" something out of its AI brain. Sometimes it can be a very critical piece of info.
     
    Spy-Master, Anthiese and Occuros like this.
  5. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    300
    Nothing wrong with using new tools like ChapGPT to help you understand or learn new things. But giving unverified advice here without rigorously testing and fully understanding beforehand is not the right path. Please stop spreading miss information.
     
    Spy-Master and Anthiese like this.