protected override JobHandle OnUpdate(JobHandle inputDeps) { //NativeQueue<CrashInfo> destroyedPlanetoidsQueue = new NativeQueue<CrashInfo>(Allocator.TempJob); EntityQuery entityQuery = GetEntityQuery(typeof(Planetoid)); NativeArray <Planetoid> planetoids = entityQuery.ToComponentDataArray <Planetoid>(Allocator.TempJob); NativeArray <int> keys = QuadrantSystem.quadrantMultiHashMap.GetKeyArray(Allocator.TempJob); NativeArray <JobHandle> jobHandles = new NativeArray <JobHandle>(keys.Length, Allocator.TempJob); for (int i = 0; i < keys.Length; i++) { NativeArray <EntityWithProps> entityWithPropsArray = new NativeArray <EntityWithProps>(QuadrantSystem.GetEntityCountInQuadrant(QuadrantSystem.quadrantMultiHashMap, keys[i]), Allocator.TempJob); SortPositionsJob sortPositionsJob = new SortPositionsJob { quadrantMultiHashMap = QuadrantSystem.quadrantMultiHashMap, entityWithPropsArray = entityWithPropsArray, realtimeSinceStartUp = Time.realtimeSinceStartup, planetoids = planetoids, keys = keys, index = i }; jobHandles[i] = sortPositionsJob.Schedule(); } JobHandle job = JobHandle.CombineDependencies(jobHandles); JobHandle.CompleteAll(jobHandles); jobHandles.Dispose(); keys.Dispose(); //destroyedPlanetoidsQueue.Dispose(); DisableJob disableJob = new DisableJob { entityCommandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent() }; JobHandle jobHandle = disableJob.Schedule(this, job);//TODO try job handles combine endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle); AddTranslationJob addTranslationJob = new AddTranslationJob { seed = UnityEngine.Random.Range(1, 1000000), realTimeSinceStartUp = Time.realtimeSinceStartup, entityCommandBuffer = endPresentationSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(), cameraMaxLeftDown = Camera.main.ViewportToWorldPoint(new Vector3(0, 0)), cameraMaxRightUp = Camera.main.ViewportToWorldPoint(new Vector3(1, 1)) }; jobHandle = addTranslationJob.Schedule(this, jobHandle); endPresentationSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle); return(jobHandle); }