I’m running into some dependency issues, but I don’t understand why. Please take a look at the following test code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
using Unity.Jobs;
using Unity.Burst;
using Unity.Collections;
public class ProducerSystemGroup : ComponentSystemGroup
{
}
[UpdateAfter(typeof(ProducerSystemGroup))]
public class ConsumerSystemGroup : ComponentSystemGroup
{
}
[UpdateInGroup(typeof(ProducerSystemGroup))]
public class ProducerSystem : JobComponentSystem
{
private NativeMultiHashMap<int, int> countsByNumerMap;
public NativeMultiHashMap<int, int> GetCountsByNumerMap()
{
return countsByNumerMap;
}
protected override void OnCreate()
{
countsByNumerMap = new NativeMultiHashMap<int, int>(10, Allocator.Persistent);
}
protected override void OnDestroy()
{
countsByNumerMap.Dispose();
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
return new ProducerJob
{
countsByNumerMap = countsByNumerMap.AsParallelWriter()
}
.Schedule(inputDeps);
}
private struct ProducerJob : IJob
{
public NativeMultiHashMap<int, int>.ParallelWriter countsByNumerMap;
public void Execute()
{
// write to map.
}
}
}
[UpdateInGroup(typeof(ConsumerSystemGroup))]
public class ConsumerSystem : JobComponentSystem
{
private ProducerSystem producerSystem;
protected override void OnCreate()
{
producerSystem = World.GetOrCreateSystem<ProducerSystem>();
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
return new ConsumerJob
{
countsByNumerMap = producerSystem.GetCountsByNumerMap()
}
.Schedule(inputDeps);
}
private struct ConsumerJob : IJob
{
public NativeMultiHashMap<int, int> countsByNumerMap;
public void Execute()
{
// read from map.
}
}
}
When run, I get the following error:
I was confused to see this, since from what I can tell, the dependency chain is set up correctly:
- ProducerSystem updates in ProducerSystemGroup.
- ConsumerSystem updates in ConsumerSystemGroup.
- ConsumerSystemGroup always updates after ProducerSystemGroup.
Wouldn’t that mean that ConsumerJob is guaranteed to be dependent on ProducerJob? Wouldn’t ProducerJob always complete before the scheduled ConsumerJob runs?
What am I missing here? Thanks for any help.