Running AstarPath.active.Scan on its own thread

Is it possible to run AstarPath.active.Scan() on its own thread? From what I can tell the Unity API won’t accept calls from any thread but the main, and I assume Scan() calls the Unity API.

If it is not possible to run on its own thread is there a suggested way to limit the impact Scan() has on the main thread without reducing the size or granularity of the Grid? I am currently getting 100-300ms spikes when the Scan() occurs and I need to re-scan my Grid every fairly often.

I’ve considered splitting my graph into a bunch of smaller graphs and scanning them one at a time. Would this be a viable option? Can a seeker find a path across multiple graphs?

What about Coroutines. Does A* Pathfinding have a Coroutine scan function?

Hi

The Scan method cannot run in its own thread since it uses the Unity API.
You can use the ScanLoop method which is slightly more granular.

Have you considered updating smaller parts of the graph: http://arongranberg.com/astar/docs/graph-updates.php
Or maybe using the ProceduralGridMover script (see the Procedural example scene).

Hi Aron,

Thanks for the response. I am actually using a smaller grid and am moving it with my AI already.

I though perhaps I could generate a “Grid of even smaller Grids” that could represent a larger are. I haven’t been able to make the AI use anything but the first grid generated though.

Do you have any examples of a seeker searching multiple grids for paths. Is there any way to tell a seeker to move from one grid to another?

Hi

I usually advise against using multiple graphs. It’s hard to handle the cases near the border between two graphs.
It can be done, but I really recommend that you try alternative solutions.

If you are moving it with your AI, make sure you check out the “Procedural” example scene which has a graph which moves with a character along an infinite world. When it is moved it only recalculates the nodes that need updating, so it is much faster than recalculating the whole graph.