[Exception] NullReferenceException: Object reference not set to an instance of an object
--- End of stack trace from previous location where exception was thrown ---
--- End of stack trace from previous location where exception was thrown ---
--- End of stack trace from previous location where exception was thrown ---
TriangleMeshNode.GetVertices() Assets/Plugins/AstarPathfindingProject/Generators/NodeClasses/TriangleMeshNode.cs:90
88: var holder = GetNavmeshHolder(GraphIndex);
-->90: v0 = holder.GetVertex(this.v0);
91: v1 = holder.GetVertex(this.v1);
92: v2 = holder.GetVertex(this.v2);
TriangleMeshNode.ClosestPointOnNode() Assets/Plugins/AstarPathfindingProject/Generators/NodeClasses/TriangleMeshNode.cs:122
120: Int3 a, b, c;
-->122: GetVertices(out a, out b, out c);
123: return Polygon.ClosestPointOnTriangle((Vector3)a, (Vector3)b, (Vector3)c, p);
124: }
BBTree.SearchBoxClosest() Assets/Plugins/AstarPathfindingProject/Generators/Utilities/BBTree.cs:357
355: for (int i = 0; i < MaximumLeafSize && nodes[box.nodeOffset+i] != null; i++) {
356: var node = nodes[box.nodeOffset+i];
-->357: Vector3 closest = node.ClosestPointOnNode(p);
358: float dist = (closest-p).sqrMagnitude;
359: if (dist < closestSqrDist) {
BBTree.QueryClosest() Assets/Plugins/AstarPathfindingProject/Generators/Utilities/BBTree.cs:342
341: if (count > 0 && SquaredRectPointDistance(tree[0].rect, p) < sqrDistance) {
-->342: SearchBoxClosest(0, p, ref sqrDistance, constraint, ref previous);
343: // Only update the distance if the squared distance changed as otherwise #distance
344: // might change due to rounding errors even if no better solution was found
NavmeshBase.GetNearestForce() Assets/Plugins/AstarPathfindingProject/Generators/NavmeshBase.cs:470
468: best = tile.bbTree.QueryClosestXZ(position, constraint, ref bestDistance, best);
469: } else {
-->470: best = tile.bbTree.QueryClosest(position, constraint, ref bestDistance, best);
471: }
472: }
NavmeshBase.GetNearest() Assets/Plugins/AstarPathfindingProject/Generators/NavmeshBase.cs:422
421: public override NNInfoInternal GetNearest (Vector3 position, NNConstraint constraint, GraphNode hint) {
-->422: return GetNearestForce(position, constraint != null && constraint.distanceXZ ? NNConstraintDistanceXZ : null);
423: }
NavGraph.GetNearest() Assets/Plugins/AstarPathfindingProject/Generators/Base.cs:177
175: * \param constraint Can for example tell the function to try to return a walkable node. If you do not get a good node back, consider calling GetNearestForce. */
176: public NNInfoInternal GetNearest (Vector3 position, NNConstraint constraint) {
-->177: return GetNearest(position, constraint, null);
178: }
NavGraph.GetNearest() Assets/Plugins/AstarPathfindingProject/Generators/Base.cs:170
168: */
169: public NNInfoInternal GetNearest (Vector3 position) {
-->170: return GetNearest(position, NNConstraint.None);
171: }
RecastNavigationGraph.GetNearestNodePosition() Assets/Scripts/Systems/ExitPaths/Graphs/RecastNavigationGraph.cs:67
65: public NavGraph GetNavGraph() => graph;
-->67: public Vector3 GetNearestNodePosition(Vector3 position) => graph.GetNearest(position).clampedPosition;
69: public NavigationGraphSettings GetSettings() => settings;
Request.GetNearestNodePosition() Assets/Scripts/Systems/ExitPaths/Data/Request.cs:50
48: private float DistanceToGraph(Vector3 position) => Vector3.Distance(GetNearestNodePosition(position), position);
-->50: private Vector3 GetNearestNodePosition(Vector3 position) => Search.GetGraph().GetNearestNodePosition(position);
52: [UsedImplicitly]
Request.DistanceToGraph() Assets/Scripts/Systems/ExitPaths/Data/Request.cs:48
46: private bool WithinAllowedDistance(Vector3 position) => DistanceToGraph(position) <= AllowedDistanceToGraph;
-->48: private float DistanceToGraph(Vector3 position) => Vector3.Distance(GetNearestNodePosition(position), position);
50: private Vector3 GetNearestNodePosition(Vector3 position) => Search.GetGraph().GetNearestNodePosition(position);
Request.WithinAllowedDistance() Assets/Scripts/Systems/ExitPaths/Data/Request.cs:46
44: WithinAllowedDistance(source.transform.position) && WithinAllowedDistance(sink.transform.position);
-->46: private bool WithinAllowedDistance(Vector3 position) => DistanceToGraph(position) <= AllowedDistanceToGraph;
48: private float DistanceToGraph(Vector3 position) => Vector3.Distance(GetNearestNodePosition(position), position);
Request.WithinAllowedDistance() Assets/Scripts/Systems/ExitPaths/Data/Request.cs:44
43: private bool WithinAllowedDistance(Component source, Component sink) =>
-->44: WithinAllowedDistance(source.transform.position) && WithinAllowedDistance(sink.transform.position);
46: private bool WithinAllowedDistance(Vector3 position) => DistanceToGraph(position) <= AllowedDistanceToGraph;
Request+<Dispatch>d__4.MoveNext() Assets/Scripts/Systems/ExitPaths/Data/Request.cs:37
35: var sink = Search.GetSink();
-->37: if (!WithinAllowedDistance(source, sink))
38: return ExitPath.None;
ExceptionDispatchInfo.Throw() <f2e6809acb14476a81f399aeb800f8f2>:0
TaskAwaiter.ThrowForNonSuccess() <f2e6809acb14476a81f399aeb800f8f2>:0
TaskAwaiter.HandleNonSuccessAndDebuggerNotification() <f2e6809acb14476a81f399aeb800f8f2>:0
TaskAwaiter.ValidateEnd() <f2e6809acb14476a81f399aeb800f8f2>:0
System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult() <f2e6809acb14476a81f399aeb800f8f2>:0
SolverSimple+<WhenAllRequestsCompletedAsync>d__31.MoveNext() Assets/Scripts/Systems/ExitPaths/SolverSimple.cs:271
269: var requested = requests.All.SelectMany(sourceSink => sourceSink.Value);
270: var dispatched = requested.Select(request => request.Value.Dispatch());
-->271: var results = await Task.WhenAll(dispatched);
272: return results;
273: }
ExceptionDispatchInfo.Throw() <f2e6809acb14476a81f399aeb800f8f2>:0
TaskAwaiter.ThrowForNonSuccess() <f2e6809acb14476a81f399aeb800f8f2>:0
TaskAwaiter.HandleNonSuccessAndDebuggerNotification() <f2e6809acb14476a81f399aeb800f8f2>:0
TaskAwaiter.ValidateEnd() <f2e6809acb14476a81f399aeb800f8f2>:0
System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult() <f2e6809acb14476a81f399aeb800f8f2>:0
SolverSimple+<SolveAsync>d__27.MoveNext() Assets/Scripts/Systems/ExitPaths/SolverSimple.cs:130
128: var graph = await graphs.GetGraphAsync(new NavigationGraphSettings(agentRadius));
129: var requests = RequestSourcesToAllSinks(graph, capacitySources[capacity]);
-->130: var results = await WhenAllRequestsCompletedAsync(requests);
131: var unsuccessful = capacitySources[capacity];
ExceptionDispatchInfo.Throw() <f2e6809acb14476a81f399aeb800f8f2>:0
AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0() <f2e6809acb14476a81f399aeb800f8f2>:0
UnitySynchronizationContext+WorkRequest.Invoke() C:/buildslave/unity/build/Runtime/Export/UnitySynchronizationContext.cs:93
UnitySynchronizationContext.Exec() C:/buildslave/unity/build/Runtime/Export/UnitySynchronizationContext.cs:54
UnitySynchronizationContext.ExecuteTasks() C:/buildslave/unity/build/Runtime/Export/UnitySynchronizationContext.cs:75
I have the same issue when trying to find the nearest point in navmesh to the point in world position. Sometimes it works, sometimes it throws this error.
Here’s my log:
NullReferenceException: Object reference not set to an instance of an object
Pathfinding.TriangleMeshNode.GetVertices (Pathfinding.Int3& v0, Pathfinding.Int3& v1, Pathfinding.Int3& v2) (at Assets/Plugins/AstarPathfindingProject/Generators/NodeClasses/TriangleMeshNode.cs:94)
Pathfinding.TriangleMeshNode.ClosestPointOnNode (UnityEngine.Vector3 p) (at Assets/Plugins/AstarPathfindingProject/Generators/NodeClasses/TriangleMeshNode.cs:126)
Pathfinding.BBTree.SearchBoxClosest (System.Int32 boxi, UnityEngine.Vector3 p, System.Single& closestSqrDist, Pathfinding.NNConstraint constraint, Pathfinding.NNInfoInternal& nnInfo) (at Assets/Plugins/AstarPathfindingProject/Generators/Utilities/BBTree.cs:358)
Pathfinding.BBTree.QueryClosest (UnityEngine.Vector3 p, Pathfinding.NNConstraint constraint, System.Single& distance, Pathfinding.NNInfoInternal previous) (at Assets/Plugins/AstarPathfindingProject/Generators/Utilities/BBTree.cs:343)
Pathfinding.NavmeshBase.GetNearestForce (UnityEngine.Vector3 position, Pathfinding.NNConstraint constraint) (at Assets/Plugins/AstarPathfindingProject/Generators/NavmeshBase.cs:499)
Pathfinding.NavmeshBase.GetNearest (UnityEngine.Vector3 position, Pathfinding.NNConstraint constraint, Pathfinding.GraphNode hint) (at Assets/Plugins/AstarPathfindingProject/Generators/NavmeshBase.cs:451)
Pathfinding.NavGraph.GetNearest (UnityEngine.Vector3 position, Pathfinding.NNConstraint constraint) (at Assets/Plugins/AstarPathfindingProject/Generators/Base.cs:219)
AstarPath.GetNearest (UnityEngine.Vector3 position, Pathfinding.NNConstraint constraint, Pathfinding.GraphNode hint) (at Assets/Plugins/AstarPathfindingProject/Core/AstarPath.cs:2060)
AstarPath.GetNearest (UnityEngine.Vector3 position, Pathfinding.NNConstraint constraint) (at Assets/Plugins/AstarPathfindingProject/Core/AstarPath.cs:2025)
Thank you. Do you have a way to consistently reproduce this bug?