Time limit on calls to Synch StartPath/WaitForPath?


At some point in my code, I need to call StartPath and WaitForPath in Synch, waiting for it to complete before continuing my code. I have a layered grid graph.

When I call StartPath and WaitForPath, can I pass a time limit ? If the path I’m asking is unreachable the compute graph takes a second or two, stalling the game.

Normally the paths for the Synch calls are short. hence it doesn’t take more than a couple of milli when the path is valid.
But it happen that even if the distance is short, there is no path between the from and to, resulting in spikes in the framerate.

I would rather that if there is no path found in less than 0.5ms, my code tries something else.
Any way to limit the time for the calculate path ?



Not really. But assuming you are using multithreading you can use a spin wait and check if the path is complete within a specific time and otherwise call .Error() on the path object.

Also, if the path is unreachable the system should be able to tell you that with a constant time check which is done at the start of every path calculation. Unless you have disabled flood filling when doing graph updates for some reason.

Yes, the floodfilling is disabled.
Indeed, I’ll make myself start the AstartPath on another thread along with a timer on my side. If my timer ends first, I’ll conclude that path is not valid and the thread will end later by itself.
Hopefully, I won’t have tons of threads running !


To avoid spending more time on a path you are not going to use anyway you can call the method called Error on the path. That will cancel it.