Search Unity

Entities 0.14 - RegisterGenericJobType + job reflection data has not been automatically computed

Discussion in 'Entity Component System' started by PhilSA, Aug 15, 2020.

  1. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    EDIT: got an additional issue described here

    --------------------

    I get this error after upgrading to entities 0.14:
    I think just a simple example of how to use it would help me out
     
    Last edited: Aug 15, 2020
    saarg likes this.
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    What type of generics or custom jobs are you using in your jobs?

    I couldn't create a repo myself using generics in various ways, but looking at source it appears related to the job scheduler code gen.
     
    Last edited: Aug 15, 2020
  3. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    My use case looks like this:
    Something to note is that the system inheriting from the base generic system lives in a different assembly, which I suspect might be why I get this? It worked just fine before though

    Code (CSharp):
    1.  
    2. public class MyBaseSystem<T> : SystemBase where T : struct, IMyInterface
    3. {
    4.     public struct MyJob<T> : IJobChunk
    5.     {
    6.         public struct T MyThing;
    7.  
    8.         // .....
    9.     }
    10. }
    11.  
    12. // In another file and another assembly:
    13. public class MyCustomSystem : MyBaseSystem<MyCustomType>
    14. { }
     
    Last edited: Aug 15, 2020
  4. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
    Can't try right now, but if it is like RegisterGenericComponentTypeAttribute then the usage would be:
    [assembly: RegisterGenericJobType(typeof(MyBaseSystem<MyCustomType>))]

    In your use case
     
    PhilSA likes this.
  5. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    thanks! This got rid of the compilation errors

    But now during play this error is spammed:
    The only part of my code that is referenced in this error is "ExampleMovingPlatformSystem.cs:34"

    This appears to be unrelated to my generic jobs. Line 34 is just a call to Entities.Foreach:
    Code (CSharp):
    1.  
    2.                 Dependency = Entities // this is line 34
    3.                     .ForEach((Entity entity, ref PhysicsVelocity physicsVelocity, in PhysicsMass physicsMass, in Translation translation, in Rotation rotation, in ExampleMovingPlatform movingPlatform) =>
    4.                 {
    5.                       /// .........
    6.                 }).ScheduleParallel(Dependency);
    Sounds like 0.14 probably made some significant changes when it comes to job reflection data and I'd better revert to 0.13 for the time being.

    EDIT: actually I get one of these errors for each of my Entities.ForEach calls in my project apparently
     
    Last edited: Aug 15, 2020
  6. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
    Are you using Entities.ForEach within generic systems? Had a couple of issues with it, migrating to IJobChunk was the only way I could find to fix it
     
  7. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    No generics used anywhere in the systems where I get the new errors
     
  8. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Just out of interest, are all your foreach passed a dependency and return a dependency?
    Wondering if we can narrow it down to a specific bad code gen because I'm not getting any errors in any of my libraries after upgrading. Be nice to know what to avoid.
     
  9. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Yes that is the case. If anything this might still be caused by another generic job somewhere in the dependency
     
  10. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Wondering if there are any updates on this. I am almost certain it is caused by the combination of using Unity 2020.2 and Entities 0.14. The problem does not appear with 2020.1 + Entities 0.14, or with 2020.2 + Entities 0.13

    So for now I either can't upgrade to 2020.2, or can't upgrade to Entities 0.14
     
  11. deplinenoise

    deplinenoise

    Unity Technologies

    Joined:
    Dec 20, 2017
    Posts:
    33
    Hi, you're right that we made substantial changes to reflection data in 0.14 and unfortunately some bugs crept in.

    We have landed a couple of fixes to the reflection data post processor after we discovered the issues and the next release should sort it out. In the mean time the workarounds are: stick with 0.13, rewrite to be non-generic or stick with 2020.1, as you point out.

    Sorry for the trouble!
     
    PhilSA likes this.
  12. MaNaRz

    MaNaRz

    Joined:
    Aug 24, 2017
    Posts:
    117
    I had the same issue with a generic IJobChunk. What i did for now is using the manual iteration over chunks in an IJobFor as shown in the Documentation.
     
    SubPixelPerfect likes this.
  13. saarg

    saarg

    Joined:
    Mar 9, 2017
    Posts:
    31
    I hit the same issue when updating my project so I guess I'll stay on 2020.1 for now. Thanks for the info @deplinenoise !
     
  14. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    This error hit me as well. It would be very helpful to confirm that this actually a bug, and not an intentional change going forward that will prevent us from using generic Jobs like we did in 0.13.

    Is it actually a bug?

    I pray that it is, rather than a design change. A fundamental part of our DOTS code hinges on us being able to use generic jobs without declaring all of the possible permutations ahead of time.
     
  15. SubPixelPerfect

    SubPixelPerfect

    Joined:
    Oct 14, 2015
    Posts:
    224
    Works for me this way:

    Unity 2020.2.0a21.2837 | Entites 0.14.0-preview.19

    Code (CSharp):
    1. using Unity.Burst;
    2. using Unity.Collections;
    3. using Unity.Entities;
    4.  
    5. [assembly: RegisterGenericJobType( typeof(GenericChunkJob<Cp2> ))]
    6.  
    7. public interface IFloatValCp: IComponentData{
    8.     float Value{ get; }
    9. }
    10. public struct Cp1 : IComponentData{
    11.     public float Value;
    12. }
    13. public struct Cp2 : IFloatValCp{
    14.     public float Value{ get; set; }
    15. }
    16.  
    17. public class SpecificChunkJobSystem : GenericChunkJobSystem<Cp2>{
    18.     protected override void OnCreate(){
    19.       var e = EntityManager.CreateEntity( typeof(Cp1), typeof(Cp2) );
    20.       EntityManager.SetName( e, "GenericChunkJobSystemTester" );
    21.       EntityManager.SetComponentData( e, new Cp1(){ Value = 10000 } );
    22.       EntityManager.SetComponentData( e, new Cp2(){ Value = 1} );
    23.  
    24.       base.OnCreate();
    25.     }
    26. }
    27.  
    28. public class GenericChunkJobSystem<T> : SystemBase where T: struct, IFloatValCp{
    29.     EntityQuery _query;
    30.     protected override void OnCreate(){
    31.       _query = GetEntityQuery(
    32.         ComponentType.ReadWrite<Cp1>(),
    33.         ComponentType.ReadWrite<T>()
    34.       );
    35.     }
    36.     protected override void OnUpdate(){
    37.       var job = new GenericChunkJob<T>{
    38.         Cp1TypeHandle = GetComponentTypeHandle<Cp1>(),
    39.         TTypeHandle = GetComponentTypeHandle<T>(true)
    40.       };
    41.       Dependency = job.ScheduleParallel(_query, Dependency);
    42.     }
    43. }
    44.  
    45. [BurstCompile]
    46. public struct GenericChunkJob<T> : IJobChunk  where T: struct, IFloatValCp{
    47.     public ComponentTypeHandle<Cp1> Cp1TypeHandle;
    48.     [ReadOnly] public ComponentTypeHandle<T> TTypeHandle;
    49.  
    50.     public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex ){
    51.       var chunkCp1 = chunk.GetNativeArray(Cp1TypeHandle);
    52.       var chunkT = chunk.GetNativeArray(TTypeHandle);
    53.       var instanceCount = chunk.Count;
    54.  
    55.       for (int i = 0; i < instanceCount; i++){
    56.        var cp1 = chunkCp1[i];
    57.        cp1.Value += chunkT[i].Value;
    58.        chunkCp1[i] = cp1;
    59.       }
    60.     }
    61. }
     
    Last edited: Sep 21, 2020
  16. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    I may be assuming the wrong thing about the RegisterGenericJobTypeAttribute. Based on Joachim’s comments in some other threads, I had been assuming any and all generic jobs were now intentionally undetected to Burst, unless you use this attribute.

    @tertle, are you saying that, using Entities 0.14 and Unity 2020.2b (or later), you’re able to use at least some generic jobs like you did in 0.13, without the use of RegisterGenericJobType?
     
  17. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    https://forum.unity.com/threads/wil...neric-jobs-going-forward.974187/#post-6353508

    Commented here I finally ran into a use case where this popped up, though the bug annoyed me more.

    But to be honest I use very few (if any) generic job/systems
     
    PublicEnumE likes this.
  18. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
  19. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Adding the "[assembly: (...)] part solves it now:

    Code (CSharp):
    1.  
    2. [assembly: RegisterGenericJobType(typeof(MySystemAJob<MyComponentA>))]
    3.  
    4. public class MySystemA: MyBaseSystem<MyComponentA>
    5. { }
     
  20. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    Needing to add the assembly part is the problem. :( This constraint may seem fine on paper, but it has seriously messed up our code.
     
  21. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
    Not sure if my understanding is wrong or if it is a bug, but I found out that having a non-generic job inside a generic system that uses a generic argument of the system doesn't work.
    Code (CSharp):
    1. public abstract class GenericSystem<T> : SystemBase
    2. {
    3.     public struct Job : IJob
    4.     {
    5.         public T Value;
    6.  
    7.         // stuff
    8.     }
    9.  
    10.  
    11.     // stuff
    12. }
    13.  
    14. public sealed class ConcreteSystem : GenericSystem<SomeComponent>
    15. {
    16.     // stuff
    17. }
    18.  
    19. // complains that Job is not generic
    20. // but if I remove it it complains that it can't generate the reflection data for it
    21. [assembly: RegisterGenericJobType(typeof(GenericSystem<SomeComponent>.Job))]
    My solution was to remove the Job from inside the System and make it generic.

    Using 2020.2.0b4 btw.
     
  22. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    304
    Same problem, nothing seems to help, there's still the error.
    Adding attribute does not help.

    Unity 2020.2.0b11
    Entities 0.16.0
    Jobs 0.7.0

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Text;
    5. using System.Threading.Tasks;
    6. using Unity.Entities;
    7.  
    8. [assembly: RegisterGenericComponentType(typeof(AddGenericComponentJob<FindPath>))]
    9. public struct AddGenericComponentJob<T> : IJobChunk
    10.         where T : struct, IComponentData
    11. {
    12.     public T ComponentData;
    13.     public EntityCommandBuffer.ParallelWriter CmdBuffer;
    14.     public EntityTypeHandle Entities;
    15.  
    16.     public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
    17.     {
    18.         var entities = chunk.GetNativeArray(Entities);
    19.         for (int i = 0; i < chunk.Count; i++)
    20.         {
    21.             CmdBuffer.AddComponent(firstEntityIndex, entities[i], ComponentData);
    22.         }
    23.     }
    24. }
    (0,0): error error DC3002: AddGenericComponentJob`1: generic jobs cannot have their reflection data auto-registered - you must use the assembly-level RegisterGenericJobType attribute to specify which instantiations you need
     
  23. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
    You are using RegisterGenericComponentType, it should be RegisterGenericJobType.
     
    OndrejP likes this.
  24. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    304
    Thanks, now it works! I should probably learn how to read to be a better programmer :D
     
    brunocoimbra likes this.
  25. NagaChiang

    NagaChiang

    Joined:
    Sep 17, 2020
    Posts:
    13
    I have the same problem, using a non-generic job inside a generic system is not working even with the RegisterGenericJobType attribute. I'm using Unity 2020.2.1f1 with Entities 0.14.0.

    There are errors at runtime:

    Code (CSharp):
    1. BadImageFormatException: Expected reference type but got type kind 17
    2. Unity.Entities.EarlyInitHelpers.FlushEarlyInits () (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/Types/EarlyInitHelpers.cs:26)
    3. UnityEngine.Debug:LogException(Exception)
    4. Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/Stubs/Unity/Debug.cs:19)
    5. Unity.Entities.EarlyInitHelpers:FlushEarlyInits() (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/Types/EarlyInitHelpers.cs:30)
    6. Unity.Entities.EntityManager:Initialize(World) (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/EntityManager.cs:200)
    7. Unity.Entities.World:.ctor(String, WorldFlags) (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/World.cs:472)
    8. Unity.Entities.DefaultWorldInitialization:Initialize(String, Boolean) (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/DefaultWorldInitialization.cs:127)
    9. Unity.Entities.AutomaticWorldBootstrap:Initialize() (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities.Hybrid/Injection/AutomaticWorldBootstrap.cs:15)
    Code (CSharp):
    1. InvalidOperationException: IJobChunk job reflection data has not been automatically computed - this is a bug
    2. Unity.Entities.JobChunkExtensions+JobChunkProducer`1[T].InitializeParallel () (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/IJobChunk.cs:325)
    3. Unity.Entities.JobChunkExtensions.ScheduleInternal[T] (T& jobData, Unity.Entities.EntityQuery query, Unity.Jobs.JobHandle dependsOn, Unity.Jobs.LowLevel.Unsafe.ScheduleMode mode, System.Boolean isParallel) (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/IJobChunk.cs:214)
    4. Unity.Entities.JobChunkExtensions.ScheduleParallel[T] (T jobData, Unity.Entities.EntityQuery query, Unity.Jobs.JobHandle dependsOn) (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/IJobChunk.cs:150)
    5. Timespawn.EntityTween.Tweens.TweenGenerateSystem`4[TTweenCommand,TTweenInfo,TTarget,TTweenInfoValue].OnUpdate () (at C:/Workspace/entity-tween/Runtime/Tweens/Systems/TweenGenerateSystem.cs:101)
    6. Unity.Entities.SystemBase.Update () (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/SystemBase.cs:411)
    7. Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/ComponentSystemGroup.cs:513)
    8. UnityEngine.Debug:LogException(Exception)
    9. Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/Stubs/Unity/Debug.cs:19)
    10. Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/ComponentSystemGroup.cs:518)
    11. Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/ComponentSystemGroup.cs:461)
    12. Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/ComponentSystem.cs:107)
    13. Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/ComponentSystemGroup.cs:513)
    14. Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/ComponentSystemGroup.cs:461)
    15. Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/ComponentSystem.cs:107)
    16. Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/ComponentSystemGroup.cs:513)
    17. Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/ComponentSystemGroup.cs:461)
    18. Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/ComponentSystem.cs:107)
    19. Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at
     
    WAYNGames likes this.
  26. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    992
    I have similar jobs working with last entities package and Unity 2020.1.1f17 without the RegisterGenericJobType.
    Although not very clear, my understanding is that what you experience is a regression/bug that will be fixed in later version of the engine/package.

    I do experience the same behavior if I update to 2020.2.

     
    NagaChiang likes this.
  27. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
    This is not the same issue that I was having. Did you try the most recent version of the package (0.16)? Also, there is a message in the log clearly stating that this is a bug, maybe create a bug report if the error persists after the update.
     
  28. NagaChiang

    NagaChiang

    Joined:
    Sep 17, 2020
    Posts:
    13
    I have another compile-time error with Entities 0.16.0, which is about a non-generic job in a generic system:

    Code (CSharp):
    1. (0,0): error Mono.Cecil.ResolutionException: Failed to resolve DestroyJob<Timespawn.EntityTween.Tweens.TweenTranslation>