Search Unity

IJobForEach.Schedule(ComponentSystemBase) did not work correctly (p31)

Discussion in 'Entity Component System' started by Kichang-Kim, May 9, 2019.

  1. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,012
    Hi, I found that Entities 0.0.12-p31 broke my system, especially used with IJobForEach.

    When my world has two entity0, entity1, which has common ComponentA and other tag components, IJobForEach<ComponentA>.Schedule(ComponentBaseSystem) fetch only one entity. When I changed to Schedule(entityQuery), it correctly process both entities. (this example is very simplified.) With previous version, this issue did not occured.

    I think that below changes makes this issue:
    Is this intended behaviour?

    Thanks.
     
    Last edited: May 9, 2019
  2. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,012
    I figured out minimul reproducible sample code:
    Code (CSharp):
    1. [AlwaysUpdateSystem]
    2. public class TestSystem : JobComponentSystem
    3. {
    4.     EntityQuery query0;
    5.  
    6.     protected override void OnCreateManager()
    7.     {
    8.         base.OnCreateManager();
    9.  
    10.         bool createQuery = true;
    11.  
    12.         if (createQuery)
    13.         {
    14.             this.query0 = this.GetEntityQuery(new EntityQueryDesc()
    15.             {
    16.                 All = new ComponentType[] { ComponentType.ReadWrite<MyComponent>() },
    17.                 Any = Array.Empty<ComponentType>(),
    18.                 None = new ComponentType[] { ComponentType.ReadOnly<MyTag0>() },
    19.             });
    20.         }
    21.  
    22.         Entity entity0 = this.EntityManager.CreateEntity();
    23.         this.EntityManager.AddComponentData(entity0, new MyComponent { Value = 0 });
    24.         this.EntityManager.AddComponentData(entity0, new MyTag0());
    25.  
    26.         Entity entity1 = this.EntityManager.CreateEntity();
    27.         this.EntityManager.AddComponentData(entity1, new MyComponent { Value = 1 });
    28.     }
    29.  
    30.     protected override JobHandle OnUpdate(JobHandle inputDeps)
    31.     {
    32.         inputDeps = new TestJob()
    33.         {
    34.         }.Schedule(this, inputDeps);
    35.  
    36.         return inputDeps;
    37.     }
    38. }
    39.  
    40. public struct TestJob : IJobForEachWithEntity<MyComponent>
    41. {
    42.     public void Execute(Entity entity, int index, ref MyComponent c0)
    43.     {
    44.         Debug.Log(c0.Value);
    45.     }
    46. }
    47.  
    48. public struct MyComponent : IComponentData
    49. {
    50.     public int Value;
    51. }
    52.  
    53. public struct MyTag0 : IComponentData
    54. {
    55. }
    If you run this code, you can see log only value 1, then after changing createQuery to false, IJobForEach proccesses both entities finally.

    It seems that if the base system has entitiy query with EntitiyQueryDesc which include IJobForEach's architypes, IJobForEach can't fetch entities correctly. This behaviour is clearly different to previous version of Entities.

    (Tested with Unity 2019.1.1f1 + Entities 0.0.12p31)
     
    Last edited: May 9, 2019
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    I found your description and example confusing, but after running example I could replicate it and I believe that this should be considered a bug.

    Also if dive into source quickly, it appears the the job code only compares ComponentType[] not the All, And or Any parts.
     
    Last edited: May 9, 2019
    Kichang-Kim likes this.
  4. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    I'm not understanding how the query is even applied here at all. It's not being passed to Schedule.
     
  5. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Component systems cache queries.

    It's mistakenly thinking the query for the job is the same as the query that was defined earlier - which is the bug.
     
  6. AriaBonczek

    AriaBonczek

    Unity Technologies

    Joined:
    Jul 20, 2018
    Posts:
    26
    This is a bug.
    IJobForEach.Schedule(ComponentSystem, JobHandle)
    *should* always return an
    EntityQuery
    that matches exactly, but it seems like it can mistakenly choose one that matches partially. I'll make a bug report for it so we can hopefully fix this soon.
     
  7. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,012
    @AriaBonczek Hi, I checked the change log of 0.0.12-p32, but there is no fix of this. Can you provide me the current status of this issue?
     
  8. AriaBonczek

    AriaBonczek

    Unity Technologies

    Joined:
    Jul 20, 2018
    Posts:
    26
    In progress. Don't have a specific date/version #. *Soon* is the best I can do :D
     
    Kichang-Kim likes this.
  9. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,012
    Entities 0.1.0-preview still has this issue. Is this issue not critical?

    Edit: @AriaBonczek Can you provide issue number for tracking the status of this issue?
     
    Last edited: Aug 2, 2019