protected override JobHandle OnUpdate(JobHandle inputDeps)
 {
     if (agent.Length > 0)
     {
         indexMap.Clear();
         nextPositionMap.Clear();
         var hashPositionsJob = new HashPositionsJob
         {
             mapSize         = querySystem.MaxMapWidth,
             agents          = agent.Agents,
             avoidances      = agent.Avoidances,
             indexMap        = indexMap,
             nextPositionMap = nextPositionMap
         };
         var dt = Time.deltaTime;
         var hashPositionsJobHandle = hashPositionsJob.Schedule(agent.Length, 64, inputDeps);
         var avoidanceJob           = new NavAgentAvoidanceJob
         {
             dt              = dt,
             indexMap        = indexMap,
             nextPositionMap = nextPositionMap,
             agents          = agent.Agents,
             avoidances      = agent.Avoidances,
             entities        = agent.Entities,
             navMeshQuery    = navMeshQuery
         };
         var avoidanceJobHandle = avoidanceJob.Schedule(indexMap, 64, hashPositionsJobHandle);
         return(avoidanceJobHandle);
     }
     return(inputDeps);
 }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            // In theory, JobComponentSystem will by default not run OnUpdate if the agentQuery is empty to begin with.
            var agentCnt = _agentQuery.CalculateEntityCount();

            if (agentCnt > 0)
            {
                var agentEntities = _agentQuery.ToEntityArray(Allocator.TempJob);

                IndexMap.Clear();
                NextPositionMap.Clear();

                var hashPositionsJob = new HashPositionsJob
                {
                    MapSize         = _querySystem.MaxMapWidth,
                    Entities        = agentEntities,
                    Agents          = GetComponentDataFromEntity <NavAgent>(true),
                    Avoidances      = GetComponentDataFromEntity <NavAgentAvoidance>(),
                    IndexMap        = IndexMap.AsParallelWriter(),
                    NextPositionMap = NextPositionMap.AsParallelWriter()
                };
                var dt = Time.DeltaTime;
                var hashPositionsJobHandle = hashPositionsJob.Schedule(agentCnt, 64, inputDeps);
                var avoidanceJob           = new NavAgentAvoidanceJob
                {
                    DeltaTime       = dt,
                    indexMap        = IndexMap,
                    nextPositionMap = NextPositionMap,
                    Agents          = GetComponentDataFromEntity <NavAgent>(),
                    Entities        = agentEntities, // Set to deallocate
                    NavMeshQuery    = _navMeshQuery
                };
                var avoidanceJobHandle = avoidanceJob.Schedule(IndexMap, 64, hashPositionsJobHandle);


                return(avoidanceJobHandle);
            }
            return(inputDeps);
        }