Schedule IJobChunk within generic System

I’m trying to write my first generic System in which I want to schedule an IJobChunk and can’t figure it out.
I get no compilation errors but as soon as I hit play I get these Errors:

Error1

BadImageFormatException: Expected reference type but got type kind 17
Unity.Entities.EarlyInitHelpers.FlushEarlyInits () (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/Types/EarlyInitHelpers.cs:26)
UnityEngine.Debug:LogException(Exception)
Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/Stubs/Unity/Debug.cs:19)
Unity.Entities.EarlyInitHelpers:FlushEarlyInits() (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/Types/EarlyInitHelpers.cs:30)
Unity.Entities.EntityManager:Initialize(World) (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/EntityManager.cs:200)
Unity.Entities.World:.ctor(String, WorldFlags) (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/World.cs:472)
Unity.Entities.DefaultWorldInitialization:Initialize(String, Boolean) (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/DefaultWorldInitialization.cs:127)
Unity.Entities.AutomaticWorldBootstrap:Initialize() (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities.Hybrid/Injection/AutomaticWorldBootstrap.cs:15)

Error2

InvalidOperationException: IJobChunk job reflection data has not been automatically computed - this is a bug
Unity.Entities.JobChunkExtensions+JobChunkProducer`1[T].InitializeParallel () (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/IJobChunk.cs:325)
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)
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)
AIBrainSys.OnUpdate () (at Assets/Scripts/AI/Sys/AIBrainSys.cs:37)
Unity.Entities.SystemBase.Update () (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/SystemBase.cs:411)
Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/ComponentSystemGroup.cs:513)
UnityEngine.Debug:LogException(Exception)
Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/Stubs/Unity/Debug.cs:19)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/ComponentSystemGroup.cs:518)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/ComponentSystemGroup.cs:461)
Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/ComponentSystem.cs:107)
Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at Library/PackageCache/com.unity.entities@0.14.0-preview.18/Unity.Entities/ScriptBehaviourUpdateOrder.cs:333)

I get multiple Errors like Error2 for some of my unrelated Systems with “Entities.ForEach”.

Here is one example which produces this error for me:

//The Concrete Stuff
[assembly: RegisterGenericJobType
(typeof(BaseConsiderationSystem<HealthConsideration,DamageableComp>.ConsderationJob))]

public class DamageableConsiderationSys : BaseConsiderationSystem<HealthConsideration,DamageableComp> { }

public struct HealthConsideration : IComponentData { }

//The Generic Stuff
public class BaseConsiderationSystem<Consideration,Axis1> : SystemBase
    where Consideration : struct, IComponentData
    where Axis1 : struct, IComponentData
{
    private EntityQuery query;
 
    protected override void OnCreate()
    {
        query = GetEntityQuery( typeof(Consideration) , typeof(Axis1));
    }

    protected override void OnUpdate()
    {
        var job = new ConsiderationJob
        {
            considerationTypeHandle = GetComponentTypeHandle<Consideration>(false),
            considerationAxisTypeHandle =   GetComponentTypeHandle<Axis1>(false),
        };
        this.Dependency =  job.Schedule(query, this.Dependency);
    }
 
    public struct ConsiderationJob : IJobChunk
    {
         public ComponentTypeHandle<Consideration> considerationTypeHandle;
         public ComponentTypeHandle<Axis1> considerationAxisTypeHandle;

         public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
         {
             //do sth
         }
    }
}

I read through every post concerning Generics in ECS but seems like i am still missing something…

Did you file a bug report? When an error say “this is a bug” you should send it through the Bug Reporter so that Unity can take a look.

I didn’t file one yet because I figured the first Error is the whole problem and I’m doing some basic thing wrong. I’ll file a report tomorrow.

Just upgraded to 2020.2 which caused the editor to prompt me to use RegisterGenericJobType. Back in 2020.1 I had no issues with the generic systems+jobs. While searching for solutions to it I found this thread and another thread from PhilSA that seemingly have the same issue as you do.

Just thought I’d post his thread as well in case you hadn’t seen it already.

You have no issues in the editor, but it would have silently broken on some builds (eg iOS). It’s a good thing the editor is warning you.

Ah, right. I suppose platforms with limited reflection support. Gotcha.