Array index is out of range in MultiTargetPath

for (int i = 0; i < nodePaths.Length; i++) {
if (nodePaths[i] != null) {
CompleteState = PathCompleteState.Complete;
anySucceded = true;
} else {
CompleteState = PathCompleteState.Error;
}

if (callbacks != null && callbacks[i] != null) {
SetPathParametersForReturn(i);
`callbacks[i] (this);`
// In case a modifier changed the vectorPath, update the array of all vectorPaths
vectorPaths[i] = vectorPath;
}

You are using the same index i for nodePaths.Length as you are for callbacks

I think this is the correct fix
if (callbacks != null)
{
for (int j = 0; j < callbacks.Length; j++)
{
SetPathParametersForReturn(i);
callbacks[j](this);

// In case a modifier changed the vectorPath, update the array of all vectorPaths
vectorPaths[i] = vectorPath;
}
}

Hi

Are you simply suggesting that I should rename the ‘i’ variable to ‘j’?
Having 2 variables named the same thing shouldn’t cause any issues.
Could you post the exact error message that you are getting?

The subject is the error message. Please look at your code. You are using i as the index into nodePaths.Length. You are also using it as the index into callbacks. Since they are different length arrays it crashes.

Only a part of it. It is missing a lot of useful information such as the stack trace.

I think the nodePaths array should have the same length as the callbacks array unless the path has been incorrectly configured. The constructor doesn’t validate this at the moment however, which it probably should (I have added validation to my dev version now). How are you creating the path?

I was using MultiTargetPath.callbacks incorrectly. I thought it was the number of callbacks that I wanted to be called back, not a callback per node, because I didn’t read the comment.

Ok. Great that it is resolved now.
I have added validation in the constructor now that the array lengths are equal, so hopefully this will be less likely to cause issues for any other users.