Search Unity

[SOLVED]InvalidOperationException: Reflection data was not set up by a call to Initialize()

Discussion in 'Entity Component System' started by Sylmerria, May 22, 2022.

  1. Sylmerria

    Sylmerria

    Joined:
    Jul 2, 2012
    Posts:
    369
    Hi,

    I have a problem to schedule an IJobEntityBatch when my class inherit from a generic SystemBase class.
    When I merge both classes, the code runs fine but separated not at all and the error is more an internal than a real error for the user.

    Any idea ?

    Thanks for your time :)

    Error thrown :
    Code (CSharp):
    1. public abstract partial class Foo<T> : SystemBase where T : unmanaged, IComponentData
    2. {
    3.     protected EntityQuery query;
    4.  
    5.     /// <inheritdoc />
    6.     protected override void OnCreate()
    7.     {
    8.         query = GetEntityQuery(ComponentType.ReadWrite<T>());
    9.     }
    10.  
    11.     /// <inheritdoc />
    12.     protected sealed override void OnUpdate()
    13.     {
    14.         JobEntityBatchFoo v = new JobEntityBatchFoo();
    15.         v.ComponentTTypeHandle = GetComponentTypeHandle<T>();
    16.         Dependency             = v.Schedule(query, Dependency);
    17.  
    18.         AddJobHandleForProducer(Dependency);
    19.     }
    20.  
    21.     protected abstract void AddJobHandleForProducer(JobHandle inputDeps);
    22.  
    23.     [BurstCompile]
    24.     public struct JobEntityBatchFoo : IJobEntityBatch
    25.     {
    26.         public ComponentTypeHandle<T> ComponentTTypeHandle;
    27.  
    28.         public void Execute(ArchetypeChunk batchInChunk, int batchIndex)
    29.         {
    30.             NativeArray<T> itemArray = batchInChunk.GetNativeArray(ComponentTTypeHandle);
    31.  
    32.             for (int i = 0; i < batchInChunk.Count; i++)
    33.             {
    34.                 T item = itemArray[i];
    35.                 item         = default(T);
    36.                 itemArray[i] = item;
    37.             }
    38.         }
    39.     }
    40. }

    Code (CSharp):
    1. public partial class TestSystem : Foo<Item>
    2. {
    3.     protected override void OnCreate()
    4.     {
    5.         base.OnCreate();
    6.  
    7.         Barrier = World.GetOrCreateSystem<BeginInitializationEntityCommandBufferSystem>();
    8.        
    9.         var e    = EntityManager.CreateEntity();
    10.         var item = new Item();
    11.         EntityManager.AddComponentData(e, item);
    12.     }
    13.  
    14.     protected override void AddJobHandleForProducer(JobHandle inputDeps)
    15.     {
    16.         Barrier.AddJobHandleForProducer(inputDeps);
    17.     }
    18.  
    19.     public EntityCommandBufferSystem Barrier;
    20. }
    21.  
    22. public struct Item : IComponentData
    23. {
    24.     public float3 Center;
    25.     public float3 Size;
    26. }
     
  2. Jpritch71

    Jpritch71

    Joined:
    Mar 4, 2014
    Posts:
    11
    Sylmerria likes this.
  3. Sylmerria

    Sylmerria

    Joined:
    Jul 2, 2012
    Posts:
    369
    @Jpritch71 I tried that yesterday without success but this morning that works :D thanks :)
    Edit: I know why that was not working yesterday, I used RegisterGenericComponentTypeAttribute in place of RegisterGenericJobTypeAttribute because of a missing assembly def ref missing in my asmdef -_-

    For Unity dev, Can you set a more explicite message because if you don't known what RegisterGenericJobTypeAttribute do, it's not clear what cause this assert message
     
    Last edited: May 23, 2022