NullReference in AIPathAlligntoSurface Script

I have a physics based project. Sometimes it weirdly happens that an Agent clips through the ground mesh and after that happens there is a Null Refernce in the AIPathAlligntoSurface Script in Line 51.
Any way that i could catch that error so i can prevent this ?

Which version of the package are you using?

Currently using : 5.0.6

Hi

Line numbers change a lot between versions, and due to different build steps. Would you mind posting the contents of the line that causes the error?
The full stack trace would be useful as well.

Sure:


Hi

You said you were using 5.0.6, but from the stack trace it looks like you are using an older version: 4.3.70. I’d try upgrading first.

It was an older screenshot i found because its not so easy to reproduce. Im using 5.0.6.

I see. Well, even that screenshot seems strange. Firstly because your highlighted line cannot throw an ArgumentOutOfRangeException, secondly because the line number that you have highlighted is not the line number in the stack trace below, and thirdly because even line 51 cannot throw an ArgumentOutOfRange exception, from what I can tell. Are you sure everything is correct?

I managed to reproduce it:


^^ heres the first NullReference that happens only once the Agent is inside a mesh

After that theres an error every frame here (Caused by the empty list i guess) :

You are not modifying any meshes during runtime, are you?

None that i would be aware of. No.

Ah. I think I figured it out.
If the meshcollider is convex, and the raycast starts inside it, then unity will set the triangleIndex to -1. Completely undocumented, of course. But that’s what seems to happen. I can reproduce it.

I’ll include a fix in the next update.
Thanks!

Thanks for your time :wink: