I’ve got an IJobEntity called from an OnUpdate method on an ISystem I created.
I read this error was common back when ECS was in beta like 2 or 3 years ago.
MyClass+MyJob.__ThrowCodeGenException () (at JobEntityGenerator/Unity.Entities.SourceGen.JobEntityGenerator.JobEntityGenerator/Temp/GeneratedCode/Assembly-CSharp/MyClass_Bla_bla__JobEntity_30018136860.g.cs:96)
Exception: This method should have been replaced by source gen.
So it can generate code for this particular job: i removed private content but the native array is in reality a struct that hides a nativearray inside with a struct of data (floats, all of them). This job does this:
[BurstCompile]
public partial struct MyJob : IJobEntity
{
public NativeList<MyStruct> data;
public void Execute(in AComponent id, in BComponent b)
{
data.Add(new MyStruct(a.val, b.val) });
}
}
[Edit]
I found the generated file from ECS. It contains a call to show that log for every Job related call. So it’s not generating the code.
....
global::Unity.Jobs.JobHandle __ThrowCodeGenException() => throw new global::System.Exception("This method should have been replaced by source gen.");
// Emitted to disambiguate scheduling method invocations
public void Run() => __ThrowCodeGenException();
public void RunByRef() => __ThrowCodeGenException();
public void Run(global::Unity.Entities.EntityQuery query) => __ThrowCodeGenException();
public void RunByRef(global::Unity.Entities.EntityQuery query) => __ThrowCodeGenException();
public global::Unity.Jobs.JobHandle Schedule(global::Unity.Jobs.JobHandle dependsOn) => __ThrowCodeGenException();
public global::Unity.Jobs.JobHandle ScheduleByRef(global::Unity.Jobs.JobHandle dependsOn) => __ThrowCodeGenException();
public global::Unity.Jobs.JobHandle Schedule(global::Unity.Entities.EntityQuery query, global::Unity.Jobs.JobHandle dependsOn) => __ThrowCodeGenException();
public global::Unity.Jobs.JobHandle ScheduleByRef(global::Unity.Entities.EntityQuery query, global::Unity.Jobs.JobHandle dependsOn) => __ThrowCodeGenException();
public void Schedule() => __ThrowCodeGenException();
public void ScheduleByRef() => __ThrowCodeGenException();
public void Schedule(global::Unity.Entities.EntityQuery query) => __ThrowCodeGenException();
...
So yeah, it’s not able to generate anything from that job. Why? Is there any way to see the errors in generation?
[Edit]
So I’m starting to think that I’m not using IJobEntity the way it’s supposed to be used. I’m using an external NativeArray without an index. Maybe I should write a particular IJobChunk or another type of parallel job and pass the contents of the chunks. Because I’m not really doing ECS stuff here, I’m just gathering stuff from entities components and putting it outside of the chunks.