When dealing with large graphs, computing paths can take a lot of time, even halting the game for a couple of seconds. This could ruins its overall experience, to say the least. Luckily enough there are methods to avoid this.
Note
This recipe is built on top of the principle of using coroutines as a method to keep the game running smoothly while finding a path in the background; some knowledge about coroutines is required.
We'll learn how to implement path-finding techniques using coroutines by refactoring the A* algorithm learned previously, but we will handle its signature as a different function.
Even though this recipe is only defining a function, please take into consideration the comments in the code to understand the indentation and code flow more effectively:
Modify the
Graph
class and add a couple of member variables. One for storing the path and the other to know whether the coroutine has finished...