I'm trying to write to a component data array that's come from a query in a IJobParallelFor, but it's not doing anything. I'm a little dizzy and lost searching through the docs at this stage, so would appreciate any pointers into what I'm doing wrong!
Here's a minimal example of where I've ended up. Logs on next message because I'm out of letters here.
public partial class TestSystem : SystemBase
{
struct DoMovementJibJob : IJobParallelFor
{
public NativeArray<MovementData> MovementDatas;
public void Execute(int index)
{
UnityEngine.Debug.Log($"1 {MovementDatas[index].SkipNextTick}");
var movementData = MovementDatas[index];
if (movementData.SkipNextTick)
{
UnityEngine.Debug.Log($"1a");
movementData.SkipNextTick= false;
MovementDatas[index] = movementData;
UnityEngine.Debug.Log($"1b {MovementDatas[index].SkipNextTick}");
return;
}
UnityEngine.Debug.Log($"2");
}
}
EntityQuery _query;
protected override void OnCreate()
{
base.OnCreate();
_query = EntityManager.CreateEntityQuery(ComponentType.ReadWrite<MovementData>());
}
protected override void OnUpdate()
{
UnityEngine.Debug.Log($"TICK {MRefs.Ctx.Tick}"); // Tick is the tick number, e.g. 1 then 2 then 3
var rwMovementDatas = _query.ToComponentDataArray<MovementData>(Allocator.TempJob);
new DoMovementJibJob
{
MovementDatas = rwMovementDatas,
}.Schedule(arrayLength: rwMovementDatas.Length, innerloopBatchCount: 5).Complete();
UnityEngine.Debug.Log($"TICK COMPLETE");
}
}