I am about to try to implement a pathfinding mechanic into my project and I feel it is very computationally intensive. Even otherwise, I’d like to know how to allow new frames to load before a method has finished executing. In other words, let’s say my method takes 5 seconds to execute, but I don’t need its results in this very frame. To illustrate, the execution order would look like this:
frame #5000: unit A calls method pathfinder() which takes 2 seconds to find the optimal path
frame #5001: pathfinder() is running…
.
.
.
frame #5119: pathfinder() is running…
frame #5120: pathfinder() has finished, unit now knows where to go
How do I let the game continue while the method does its thing? Doing this via coroutines sounds like it would require manually calling yield
at key points in the execution, which seems impractical. What am I missing?