Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug [0.51] Invalid deps error: WithChangeFilter x entityInQueryIndex (codeGen)

Discussion in 'Entity Component System' started by Elfinnik159, Jul 8, 2022.

  1. Elfinnik159

    Elfinnik159

    Joined:
    Feb 24, 2013
    Posts:
    145
    Hi! I submitted a bug report to Unity. This topic is for those who may have encountered this problem when upgrading to a new version. Might save someone some time.

    I ran into a lot of dependency errors after migrating my project to a new version. I searched for a reason for a long time, in the end I was able to localize the error. And it looks like it's a false error which is confusing.
    I was able to repeat this bug in an empty project, but under certain conditions:
    If there is a ForEach in the code that uses WithChangeFilter, and it has an int entityInQueryIndex in its arguments, provided that there is another ForEach before that, CodeGen will throw a false random error that the dependencies are broken.
    Code example:
    Code (CSharp):
    1.  
    2. public partial class WithChangeFilgerBug : SystemBase
    3. {
    4.     protected override void OnUpdate()
    5.     {
    6.         Entities.WithName("TranslateWithFilterJob").WithAll<TestFilter>().ForEach((Entity e, int entityInQueryIndex, ref Translation t) =>
    7.        {
    8.            t.Value = 10;
    9.        }).Schedule();
    10.  
    11.         Entities.WithName("UpdateChangedJob").WithChangeFilter<Translation>().ForEach((Entity e, int entityInQueryIndex, in Translation t) =>
    12.            {
    13.                var temp = t.Value.x;
    14.                temp += 10;
    15.            }).Schedule();
    16.     }
    17. }
    18. [GenerateAuthoringComponent]
    19. public struct TestFilter : IComponentData { }
    At the same time, if you remove entityInQueryIndex or WithChangeFilter, or if you remove ForEach before the current one, CodeGen will not show errors.
    Specifying dependencies through variables gives the same result.

    An example of an error (in different scripts it can point to completely different places):

    The system WithChangeFilgerBug writes Unity.Transforms.Translation via WithChangeFilgerBug:TranslateWithFilterJob_Job but that type was not assigned to the Dependency property. To ensure correct behavior of other systems, the job or a dependency must be assigned to the Dependency property before returning from the OnUpdate method.