using UnityEngine;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Transforms;
public class ClosureVarCaptureTestSystem : SystemBase
{
protected override void OnUpdate()
{
NativeArray<float> testVar = new NativeArray<float>(1, Allocator.TempJob);
Entities.ForEach((ref Translation position) =>
{
testVar[0] = 1f;
}).Schedule();
Debug.Log("Test var value:" + testVar[0]);
testVar.Dispose();
}
}
returns Test var value:0
Same code with Run() instead of Schedule() returns Test var value:1*.*
Also one very important thing to note… It looks like you disabled the jobs debugger. It would have told you about this race condition. It’s in the job menu, it’s a bad idea to turn it off unless you are just trying to profile in the editor.
Thank you, a useful note! Unfortunately I do have JobsDebugger enabled and I do not see any notifications neither at compile time nor at runtime. Not sure what I’m doing wrong.
I think info warnings and errors are enabled. E.g. I see warning ‘IJobForEachWithEntity is obsolete’ and also Error and Info badges showing 0. Maybe to delete Library folder and rebuild dependencies and project, to get some additional info is a good idea.