RVOAgent ArgumentOutOfRangeException

Hi there, I’m using an RVOAgent modified but I’m getting this exception sometimes:

[Exception] ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
ThrowHelper.ThrowArgumentOutOfRangeException()    <7d97106330684add86d080ecf65bfe69>:0

ThrowHelper.ThrowArgumentOutOfRangeException()    <7d97106330684add86d080ecf65bfe69>:0

System.Collections.Generic.List`1[T].get_Item()    <7d97106330684add86d080ecf65bfe69>:0

RVOAgentWanderer.Update()    Assets/Scripts/AStar/RVOAgentWanderer.cs:151
150:   if (vectorPath != null && vectorPath.Count != 0) {
-->151:       while ((controller.To2D(pos - vectorPath[wp]).sqrMagnitude < moveNextDist*moveNextDist && wp != vectorPath.Count-1) || wp == 0) {
152:           wp++;

I attach the RVOAgent that I created using yours as model, this part however I didn’t modify so I don’t understand why is throwing that exception. Apparently sometimes Is trying to access to certain position to the vectorPath array that doesn’t exist.

PS: Changed the extension from cs to txt so I could upload.

Thaks and best regards.

RVOAgentWanderer.txt (7.0 KB)

Hey,

Coding wise I couldn’t find any problems with the changes you’ve made.
however line 167, you are making changes to the waypoint without updating p1 and p2.

Vector3 waypoint = Vector3.Lerp(p1, p2, t);
waypoint= new Vector3(waypoint.x, 2.4f, waypoint.z);

I think that could mess with the system not checking for PathCompleted correctly.

I’d try adding a break point into the function OnPathComplete and verify if that’s being called at all.

1 Like

I set back that field as it was, but I still get that exception once in a while.
Seems to me that the algorithm is always taking for granted that the vector path witll have always 2 elements at least
08

But the comparison there just checks if its null or > 0 . Shouldn’t we correct it to

if vectorPath!=null && vectorPath.Count>1 ?

or maybe here inside the OnPathComplete method:

09

check when the vectorPath is created and if it has < 2 waypoints call RecalculatePath() again?

What do you think?
Thanks for your concern, I appreciate it.

Found the problem, this was happening when agents where pushing other agents out of the grid bounds

1 Like

A path can technically never have less than 1 point.
A path always consists of the current position and the target position.

That was the result of being out of the grid :smiley: