MultitargetPath with AIPath

For this question I am using 4.1.9, with AIPath, Seeker, and modifiers.

Prior to movement, the AI will use MultiTargetPath to determine which points of interest it can move to and how far away they are. In the callback, it will pick one of those points, setting AIDestinationSetter.target.

However, this seems inefficient since the same path is calculated twice, once to see if it is reachable, and again by AIBase.SearchPath(). It also causes an unnecessary delay, because I have to wait for repathRate before starting on the new path.

This is my workaround, although I had to make protected functions public to do it.
multiTargetPath.SetPathParametersForReturn(pathIdx);
// Act as if a new search had been requested
aIPath.OnSearchPath();
// Run modifiers
seeker.RunModifiers(Seeker.ModifierPass.PostProcess, multiTargetPath);
// Act as if a new search had been completed
aIPath.OnPathComplete(multiTargetPath);
aiPath.lastRepath = Time.time;

Is this the right approach or is there a better way?

Hi

If it is the closest one that you pick you can simply do this:

seeker.StartMultiTargetPath(ai.position, targetPoints, false);

This relies on the AI listening for all path complete events.

If you want to handle all path calculations yourself you can set the ai.canSearch field to false.

“If you want to handle all path calculations yourself you can set the ai.canSearch field to false.”

Supposing I set ai.CanSearch to false, what is the correct procedure to pass one of the paths from MultiTargetPath so it is properly handled by Seeker, AIPath, and the various modifier?