Hey folks, I ran into an issue.
I wanted to run some code inbetween jobs. In this case it would be just to convert a queue into a loopable array.
How do I achieve this? And is there another approach?
[UpdateBefore(typeof(BuildPhysicsWorld))]
public class GravitySystem : SystemBase
{
protected override void OnUpdate()
{
var buffer = World.GetOrCreateSystem<BeginInitializationEntityCommandBufferSystem>().CreateCommandBuffer()
.ToConcurrent();
var queue = new NativeQueue<GravityWellData>();
var queueWriter = queue.AsParallelWriter();
NativeArray<GravityWell> array;
var handle = Entities.ForEach((ref Entity entity, ref GravityWell well, ref Translation translation) =>
{
queueWriter.Enqueue(new GravityWellData
{
entity = entity,
translation = translation,
velocity = EntityManager.HasComponent<PhysicsVelocity>(entity)
? EntityManager.GetComponentData<PhysicsVelocity>(entity)
: default,
well = well
});
}).ScheduleParallel(Dependency);
// new job to convert queue into a loopable array
Entities.ForEach((ref PrivateGravity gravity, ref PhysicsVelocity velocity) =>
{
if (gravity.targetGravityWell == Entity.Null)
{
//loop array, assign closest well
}
//apply gravity
}).ScheduleParallel(handle);
}
}
thanks