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

Feedback Jobs: allow multiple scheduled ForEach with same component but when query is not overlapping

Discussion in 'Entity Component System' started by SirSyriusz, Dec 27, 2020.

  1. SirSyriusz

    SirSyriusz

    Joined:
    Aug 9, 2020
    Posts:
    11
    Hi.

    It could be handy to allow jobs referencing same component BUT when WithNone make it impossible to use at same entity. For example I have similar structure to this:
    Code (CSharp):
    1. var job1 = Entities.WithNone<compA>().ForEach((ref modifiedComponent, in compB)...).schedule();
    2. var job2 = Entities.WithNone<compB>().ForEach((ref modifiedComponent, in compA)...).schedule();
    3. JobHandle.CompleteAll(ref job1, ref job2);
    As you can see, the job1 and job2 will never use same entities, since job1 will use all that have compB but not compA, and job2 will use only those that have compA but not compB.
     
  2. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    863
    The problem is, that safety system doesn't know and could not know if there are any entities, that have modifiedComponent and have no compA and compB at the same time (in this case they will get into both queries). So I think it will be not possible.
     
  3. SirSyriusz

    SirSyriusz

    Joined:
    Aug 9, 2020
    Posts:
    11
    BUT! in the job1 you have in compB, so it will not run without it, and in job2 you have in compA. So the code will not run without compA or compB.

    If we would only limit ourselves to WithAll* and WithNone we would only need to check if there are 2 or more same component queries. If we would try to allow WithAny then it would be trickier, but we would just need to create copies for each permutation of WithAny and add it to the check. But even with that, WithAny accepts only 5 components, so in worse case scenario, that would probably never happen, produce 5*4*3*2 = 120 copies that would need to be checked once by compiler.

    Of course, there could be any number of reasons why the Unity could not do this, but I do not think that it is just impossible.
    *WithAll including components from ForEach((xxx)...
     
  4. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    That's where you use WriteGroup
    https://docs.unity3d.com/Packages/com.unity.entities@0.16/manual/ecs_write_groups.html
    But WriteGroup will not help you magically combine none-overlaping query.
    Here's what I have requested
    https://forum.unity.com/threads/can...e-for-optional-component.973539/#post-6356439
    The only choice for now is to use IJobChunk and use chunk.Has() to filter chunks.
    And you can put your logic in a function and reuse then in different case.
     
  5. SirSyriusz

    SirSyriusz

    Joined:
    Aug 9, 2020
    Posts:
    11
    Thanks, I will look into it. It seems like we had same idea, I was just lazy and hoped that Unity would do everything for me ;-).