private static void CompletePathSearch(int jobIndex, Entity entityRequest, NavMeshQuery query,
                                                   EntityCommandBuffer.Concurrent commandBuffer, int pathSize, int maximumPoolSize,
                                                   NavMeshPathfindingRequestData request, DynamicBuffer <PathBufferElement> agentPathBuffer)
            {
                var resultPath = new NativeArray <PolygonId>(pathSize, Allocator.Temp);

                query.GetPathResult(resultPath);

                //Extract path from PolygonId list
                var straightPathCount = 0;
                var straightPath      = ExtractPath(query,
                                                    request.Start, request.Destination,
                                                    resultPath, maximumPoolSize, ref straightPathCount);

                //Put the result path into buffer
                for (int i = 0; i < straightPathCount; i++)
                {
                    agentPathBuffer.Add(new PathBufferElement {
                        Value = straightPath[i].position
                    });
                }

                straightPath.Dispose();
                resultPath.Dispose();

                request.Status = PathSearchStatus.Finished;
                commandBuffer.SetComponent(jobIndex, entityRequest, request);
            }
            private static void StartPathSearch(int jobIndex, Entity entityRequest, NavMeshQuery query,
                                                EntityCommandBuffer.Concurrent commandBuffer, NavMeshPathfindingRequestData request)
            {
                var from = query.MapLocation(request.Start, request.Extents, request.AgentTypeId);
                var to   = query.MapLocation(request.Destination, request.Extents, request.AgentTypeId);

                query.BeginFindPath(from, to);
                request.Status = PathSearchStatus.Started;
                commandBuffer.SetComponent(jobIndex, entityRequest, request);
            }