For the sake of easy extensibility, I often end up using a pattern of making abstract generic systems that take certain generic types and uses those types in jobs. Something like this (the example is probably over-simplified)
Code
public interface IEventLauncher
{
void OnFireEvent(EntityCommandBuffer.Concurrent ecb);
bool ShouldFireEvent();
}
public struct FireSomeEventWhenTrue : IComponentData, IEventLauncher
{
public bool DoFireEvent;
public void OnFireEvent(EntityCommandBuffer.Concurrent ecb)
{
// create an event entity....
}
public bool ShouldFireEvent()
{
return DoFireEvent;
}
}
public class MyEventSystem<T> : JobComponentSystem where T : struct, IComponentData, IEventLauncher
{
[BurstCompile]
public struct MySystemJob : IJobForEach<T>
{
public EntityCommandBuffer.Concurrent ECB;
public void Execute(ref T eventFirer)
{
if(eventFirer.ShouldFireEvent())
{
eventFirer.OnFireEvent(ECB);
}
}
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
return new MySystemJob().Schedule(this, inputDeps);
}
}
public class MyFireSomeEventWhenTrueSystem : MyEventSystem<FireSomeEventWhenTrue>
{
}
This works perfectly in editor, but seems to fail in builds (Win64). Is this something that will work eventually?
I also haven’t yet tested if using IJobChunks instead of IJobForEachs solves the problem