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

Jobs vs Entities.ForEach..

Discussion in 'Entity Component System' started by MidnightCow, Sep 22, 2021.

  1. MidnightCow

    MidnightCow

    Joined:
    Jun 2, 2017
    Posts:
    30
    Hi,

    I've seen people use a mixture of custom Jobs and Entities.ForEach and was wondering, what are the advantages of either method.

    I think the ForEach method has a limit on parameters so i guess that's one reason to use a Job in certain situations.. On the other hand there is obviously a lot more boilerplate code when setting up Jobs so that would be one reason to prefer ForEach where possible..

    Any input appreciated. There may be other technical reasons i'm not aware of a fairly new to both systems.
     
    Lukas_Kastern likes this.
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    You can actually pass a delegate to use any number of params
    https://docs.unity3d.com/Packages/c...al/ecs_entities_foreach.html#custom-delegates

    Entities.ForEach just code gens to IJobChunk (in a future Entities version this changes to IJobEntityBatch) so under the hood they're the same.

    Custom jobs however allow you to do optimizations and certain patterns on a per chunk level that you can't achieve using ForEach. Also Entities.ForEach can become quite messy in large jobs.
     
  3. MidnightCow

    MidnightCow

    Joined:
    Jun 2, 2017
    Posts:
    30
    Hmm thanks for the reply i suspected Jobs could be more flexible in some situations and i would guess where you are looking to optimize even harder. Be interesting to find some concrete examples although i'm sure i'll discover some pretty soon either way..