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.
  2. Dismiss Notice

Question Entity Job Batch Size

Discussion in 'Entity Component System' started by Nyarlathothep, Jan 20, 2023.

  1. Nyarlathothep

    Nyarlathothep

    Joined:
    Jun 13, 2013
    Posts:
    389
    In my game I have a job which is extremely expensive bit of work to do for some entities (projecting an N-Body orbital simulation ahead in time).

    At the moment I'm using an
    IJobEntity
    for this, but it doesn't do a very good job splitting up the work. I'm guessing this is because there are only a few entities which are all occupying the same chunks so they end up running sequentially.

    It seems like the way to fix this would be to use an `IJobEntityBatch` with a batch size of 1, but as far as I can see that job type has been removed. Is there a replacement or an alternative workaround?
     
  2. MaNaRz

    MaNaRz

    Joined:
    Aug 24, 2017
    Posts:
    117
    From the Changelog:
    "IJobEntityBatch.ScheduleGranularity has been deprecated; the previous default behavior of chunk-level schedule granularity will be restored. Jobs using this feature should be migrated to IJobParallelFor."
     
    Nyarlathothep likes this.
  3. Nyarlathothep

    Nyarlathothep

    Joined:
    Jun 13, 2013
    Posts:
    389
    I was worried that would be the answer. It's a lot more convenient to be able to just set a batch size on an IJobEntity than to rewrite everything into an IJobParallelFor! Oh well, I guess that's my work for tomorrow sorted!

    Thanks for the reply :)
     
  4. MaNaRz

    MaNaRz

    Joined:
    Aug 24, 2017
    Posts:
    117
    Nyarlathothep likes this.
  5. Nyarlathothep

    Nyarlathothep

    Joined:
    Jun 13, 2013
    Posts:
    389
    Actually now that I've looked at those docs more closely I don't think they solve my problem.

    The example shows how to use an IJobParallelFor to iterate over things _in chunks_. i.e. all the things within one chunk are stilll handled together. It's not obvious how to adapt that to process each individual entity on it's own.
     
  6. MaNaRz

    MaNaRz

    Joined:
    Aug 24, 2017
    Posts:
    117
    You probably need to pass in the NativeArray<Entity> you get from the chunks instead of the ChunkArray and iterate over that with a batchsize of 1.
     
    Nyarlathothep likes this.