I have a script that I modified slightly from the multitargetpath example that runs infrequently, but I am constantly getting an error that says “Canceled path because a new one was requested,” sometimes on the first time the multitargetpath function is triggered. I have listed my code below, is there something I’m missing?
Thanks for your help!
void Start() {
seeker = GetComponent<Seeker>();
}
public void StartMultiPathing() {
// get endpoints
count = currArrayVectors.arrayList.Count;
Vector3[] endPoints = new Vector3[count];
k = 0;
foreach(Vector3 _vect in currArrayVectors.arrayList) {
endPoints[k] = _vect;
k++;
}
if (!started) {
seeker.pathCallback = OnPathComplete;
started = true;
}
seeker.StartMultiTargetPath(StartingPoint, endPoints, true);
}
public void OnPathComplete(Path p) {
if (p.error) {
Debug.Log ("No path");
return;
}
MultiTargetPath mp = p as MultiTargetPath;
if (mp==null) {
Debug.Log ("No multi path target reached");
}
if (rp == null) rp = new RichPath();
rp.Initialize (seeker, mp, true, funnelSimplification);
List<Vector3>[] paths = mp.vectorPaths;
count = paths.Length;
for (int i=0; i<paths.Length; i++) {
List<Vector3> path = paths[i];
if (path == null) {
Debug.Log("path not found");
continue;
}
// stuff
}
}
}