protected override void OnUpdate() { EntityQuery entityQuery = Entities.WithAll <QuadrantEntity, Translation, FindTargetData>().ToEntityQuery(); quadrantDataHashMap.Clear(); if (entityQuery.CalculateEntityCount() > quadrantDataHashMap.Capacity) { quadrantDataHashMap.Capacity = entityQuery.CalculateEntityCount(); } NativeHashMap <Entity, QuadrantData> entityTargetHashMap = new NativeHashMap <Entity, QuadrantData>(entityQuery.CalculateEntityCount(), Allocator.TempJob); // Position Units in HashMap SetQuadrantDataHashMapJob setQuadrantDataHashMapJob = new SetQuadrantDataHashMapJob { nativeMultiHashMap = quadrantDataHashMap.ToConcurrent(), }; JobHandle setEntityHashMapJobHandle = JobForEachExtensions.Schedule(setQuadrantDataHashMapJob, entityQuery); setEntityHashMapJobHandle.Complete(); // Cycle through all Units and FindTarget FindClosestTargetJob findClosestTargetJob = new FindClosestTargetJob { targetHashMap = quadrantDataHashMap, unitTargetHashMap = entityTargetHashMap.ToConcurrent(), }; JobHandle findClosestTargetJobHandle = JobForEachExtensions.Schedule(findClosestTargetJob, entityQuery); findClosestTargetJobHandle.Complete(); SetTargetJob setTargetJob = new SetTargetJob { entityTargetHashMap = entityTargetHashMap, entityCommandBuffer = PostUpdateCommands.ToConcurrent(), }; JobHandle setTargetJobHandle = JobForEachExtensions.Schedule(setTargetJob, entityQuery); setTargetJobHandle.Complete(); entityTargetHashMap.Dispose(); //DebugDrawQuadrant(UtilsClass.GetMouseWorldPosition()); //int hashMapKey = GetPositionHashMapKey(UtilsClass.GetMouseWorldPosition()); //Debug.Log(GetEntityCountInHashMap(quadrantDataHashMap, hashMapKey)); }