OnPathCompleted to check for failed path recovery?


I would like to add some code to handle cases where the unthinkable happens, and you get a path failed error. I did see that I could check for AIPath.path.CompleteState == PathCompleteState.Error, but if I check for it within an OnPathCompleted override function, I get a path is undefined error when path fails.

Instead, I end up simply checking for whether AIPath.path == null, in order to decide whether I have to perform additional logic, to recover a seeker that may have gone astray, or just remove it from scene. Is this the best way to do this?

What do you mean by the path being undefined?

Sorry, I should have been more specific. The exact error is:

NullReferenceException: Object reference not set to an instance of an object.

It happens on this line within the override OnPathComplete() function, inside a class that extends AIPath:

if (path.CompleteState == PathCompleteState.Error) {

Nevermind, found the issue. I should have been using the path variable passed as an argument to OnPathComplete, not the class member variable AIPath.path.

1 Like