There's more...

We will learn how to modify the current Dijkstra algorithm in order to approach the problem using pre-processing techniques and optimizing the path-finding time. It can be seen as three big steps—modifying the main algorithm, creating the pre-processing function (handy in editor mode, for example), and, finally, defining the path retrieval function:

  1. Modify the main function's signature:
public int[] Dijkstra(GameObject srcObj) 
  1. Change the returning value:
return previous; 
  1. Remove the lines from step 4 of the How to do it section:
if (ReferenceEquals(node.vertex, dst)) 
{ 
    return BuildPath(src.id, node.vertex.id, ref previous); 
}

Also, delete the following line at the beginning:

Vertex dst = GetNearestVertex(dstObj.transform.position); ...

Get Unity 2018 Artificial Intelligence Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.