Finding multiple paths in a loop


I’m using the A* package for a rather simple, Fire Emblem-esque turn based strategy game. The game plays out on a grid and I use a small grid graph to control movement range, walkability and such. The system has thus far been absolutely wonderful and solved most of my movement-related problems.

However, I can’t figure out a good way to calculate the total movement range of a unit. What I’m doing right now is finding every position the unit can walk to under optimal conditions, then draw paths to each one to check if it can actually reach them. I then color each accessible square red. Examples:

The problem is that I can’t calculate the paths through a normal loop. I have to use a coroutine and pause it for a fraction of a second every time I start a new path. This makes the operation extremely slow, around five seconds at worst. I need it to be almost instantaneous since the range marker is shown and redrawn every time you move a unit.

Is there a way to calculate new paths without having to wait for the previous one to finish? Should I buy Pro and use a multi target path instead? Or am I just approaching this the wrong way? I’m a total noob when it comes to pathfinding, so I’m sure there is a much more efficient way to solve this than whatever I can come up with.


There is a better option.
Use the ConstantPath path type (at least if you are using the pro version).
The ConstantPath will calculate what nodes a path can reach which has a cost less than or equal to some specified value, so you could find all those values in a single path request.
Take a look at the PathTypes demo and test the ConstantPath option.
Here are the docs:

If your world has a uniform cost (i.e you are not using penalties of any kind), then there is an even simpler option (which is also included in the free version):
Make sure you are using the latest version of the project (the beta) as the BFS method had some serious bugs in previous versions.

This is fantastic. I just implemented the BFS method, it works perfectly. So much faster and simpler than my stupid solution. I don’t need penalties right now, but I’ll look into buying Pro once I do. Thanks a lot, both for the solution and your amazing pathfinding kit. This project couldn’t have happened without it.