I keep Getting Argument is out of range When NPC is near Edge

Once in a while when an NPC is chasing the player and the player enters a no graph zone, this error occurs.

The NPC is near the edge of the graph, I don’t know if its because it fell out of the graph or what happens there, hope you can help me, thanks!

ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[Pathfinding.GraphNode].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
Pathfinding.RichFunnel.SimplifyPath (IRaycastableGraph graph, System.Collections.Generic.List`1 nodes, Int32 start, Int32 end, System.Collections.Generic.List`1 result, Vector3 startPoint, Vector3 endPoint) (at Assets/AstarPathfindingProject/Core/AI/RichPath.cs:331)
Pathfinding.RichFunnel.BuildFunnelCorridor (System.Collections.Generic.List`1 nodes, Int32 start, Int32 end) (at Assets/AstarPathfindingProject/Core/AI/RichPath.cs:231)
Pathfinding.RichPath.Initialize (Pathfinding.Seeker seeker, Pathfinding.Path path, Boolean mergePartEndpoints, Boolean simplificationMode) (at Assets/AstarPathfindingProject/Core/AI/RichPath.cs:98)
Pathfinding.RichAI.OnPathComplete (Pathfinding.Path p) (at Assets/AstarPathfindingProject/Core/AI/RichAI.cs:219)
Pathfinding.Seeker.OnPathComplete (Pathfinding.Path p, Boolean runModifiers, Boolean sendCallbacks) (at Assets/AstarPathfindingProject/Core/AI/Seeker.cs:299)
Pathfinding.Seeker.OnPathComplete (Pathfinding.Path path) (at Assets/AstarPathfindingProject/Core/AI/Seeker.cs:267)
Pathfinding.Path.ReturnPath () (at Assets/AstarPathfindingProject/Core/Path.cs:728)
Pathfinding.Path.Pathfinding.IPathInternals.ReturnPath () (at Assets/AstarPathfindingProject/Core/Path.cs:782)
Pathfinding.PathReturnQueue.ReturnPaths (Boolean timeSlice) (at Assets/AstarPathfindingProject/Core/Misc/PathReturnQueue.cs:55)
AstarPath.Update () (at Assets/AstarPathfindingProject/Core/AstarPath.cs:792)

I get a lot of these errors too, although I hadn’t realised it was related to the proximity of the nav edge. Here’s an example of mine (using AIPathAlignedToSurface):

ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[System.Int32].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
Pathfinding.AIPathAlignedToSurface.InterpolateNormal (RaycastHit hit) (at Assets/AstarPathfindingProject/Behaviors/AIPathAlignedToSurface.cs:48)
Pathfinding.AIPathAlignedToSurface.UpdateMovementPlane () (at Assets/AstarPathfindingProject/Behaviors/AIPathAlignedToSurface.cs:64)
Pathfinding.AIPathAlignedToSurface.Update () (at Assets/AstarPathfindingProject/Behaviors/AIPathAlignedToSurface.cs:14)

Hi

Interesting. I haven’t been able to replicate either of those errors. Would it be possible for you to share a test scene with me in which it is possible to replicate it easily?

I’m trying to make a test scene where the error can be replicated in the meantime this is the code I get.

ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List1[Pathfinding.GraphNode].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633) Pathfinding.RichFunnel.SimplifyPath (IRaycastableGraph graph, System.Collections.Generic.List1 nodes, Int32 start, Int32 end, System.Collections.Generic.List1 result, Vector3 startPoint, Vector3 endPoint) (at Assets/AstarPathfindingProject/Core/AI/RichPath.cs:331) Pathfinding.RichFunnel.BuildFunnelCorridor (System.Collections.Generic.List1 nodes, Int32 start, Int32 end) (at Assets/AstarPathfindingProject/Core/AI/RichPath.cs:231)
Pathfinding.RichPath.Initialize (Pathfinding.Seeker seeker, Pathfinding.Path path, Boolean mergePartEndpoints, Boolean simplificationMode) (at Assets/AstarPathfindingProject/Core/AI/RichPath.cs:98)
Pathfinding.RichAI.OnPathComplete (Pathfinding.Path p) (at Assets/AstarPathfindingProject/Core/AI/RichAI.cs:219)
Pathfinding.Seeker.OnPathComplete (Pathfinding.Path p, Boolean runModifiers, Boolean sendCallbacks) (at Assets/AstarPathfindingProject/Core/AI/Seeker.cs:299)
Pathfinding.Seeker.OnPathComplete (Pathfinding.Path path) (at Assets/AstarPathfindingProject/Core/AI/Seeker.cs:267)
Pathfinding.Path.ReturnPath () (at Assets/AstarPathfindingProject/Core/Path.cs:728)
Pathfinding.Path.Pathfinding.IPathInternals.ReturnPath () (at Assets/AstarPathfindingProject/Core/Path.cs:782)
Pathfinding.PathReturnQueue.ReturnPaths (Boolean timeSlice) (at Assets/AstarPathfindingProject/Core/Misc/PathReturnQueue.cs:55)
AstarPath.Update () (at Assets/AstarPathfindingProject/Core/AstarPath.cs:792)

Today I find out that one of the errors is related to the RVO system and the other to the “Funnel Simplification” option in the “Rich AI” script.
I hope this information might be useful.

I made a simple test scene to show the exceptions. I have not yet heard from Aron about this, not even whether he could reproduce the exceptions. I’d appreciate someone else on this thread trying my test and confirming that they too also see the exceptions (it happens when the player object warps from the cave to the surface in scene1).

I can confirm the error appears every single time.

1 Like

Hi

Do you have an example scene I could try out @Toto. I haven’t been able to replicate that exception.
I have managed to fix the exception that @Snouto talks about, but it is unfortunately completely unrelated.

After several fail intents, we have decided not to use RVO system and try other alternatives to avoid NPCs to collide with each other.

Sorry for the bump, but I’ve encountered the issue in 4.2.2 and did a bit of debugging.

Apparently the villain is RichPath.cs:337 (in this version), where the penalty is calculated. result[result.Count-1] != nodes[mn] throws the exception because result is empty.

It seems to occur semi-randomly in my scene, but always when startPoint and endPoint of SimplifyPath were close to each other (i.e. Vector3.Distance(startPoint, endPoint): 9.440894E-06). The location happens to be close to the edge of the graph, although I am not certain if that’s any indicator. It doesn’t seem to matter what path I am using; in the example I was trying to move from (-7.2, 0.1, 2.0) to (-7.3, 0.0, 6.0). I believe it always occurs at the end of the path, after the agent has reached the destination.

For example, this is the place of the agent when the exception was thrown. The distance between the destination and the agent was (0, 0.05, 0); for some reason the agent is floating that much above the ground and I’m not quite sure why.

image

I’ve added a log line to dump the important-ish values:

result.Count == 0: Distance 0.0004626217; start 0; end 2; 3 nodes
result.Count == 0: Distance 6.588813E-05; start 0; end 4; 5 nodes
result.Count == 0: Distance 4.046097E-06; start 0; end 4; 5 nodes

There’s just one RVO controller in the scene right now, along with a recast graph and some navmesh cuts (the square in the picture is one of those). I’m not sure if I can isolate this scene I have here into a simple test case, but maybe those hints can help?

1 Like

Heya, just adding to the pile that I’ve also been encountering this issue! I can see about making a test scene if it’d help with isolating the issue. To add onto MisterBawks notes on the issue, I added a try/catch and it seems to trigger it when accessing the List parameter at the end of the function with the list access of “result[result.Count-1]”. No clue how that would be out of range at least from just looking at the function itself, maybe something with the multithreading?

Also at least for me turning off multithreading seems to have solved it? So most likely that list is having elements removed in another thread which is causing the exception.

Edit: Nope false alarm, still happens