AstarPath.active.Scan() Async alternative?

Hello!

I have been trying to create a loading scene for a randomly generated level. I have been able to batch up my level creation code and have had pretty good success with keeping an active loading screen with animations.

The last part I have hanging is everything locking up for about 12 seconds for this method AstarPath.active.Scan(). The scenes have varying height and random terrain, do you have any suggestions for running this on a randomly created level without locking the entire frame?

It looks like half of the time is in the “graph.ScanInternal” method and the other half is in the other half is in the “FloodFill” method. I was able to identify that “FloodFill” will work when thrown into a new thread and returning the rest of the scan method back to the main thread in a delegate to run when the FloodFill thread has completed. Another though I had was to maybe even batch up some of the tasks of ScanInternal (toss back each Depth/Width iteration of ScanInternal as a delegate to the main thread and batch in chunks each frame)

After going so far down that route I decided to just ask and see if you have any suggestions for this scenario, any suggestions?

I too was asking the same question on the other thread.

We need some way to do async scan on our graphs.

One thing I was thinking would be to create a bunch of smaller grids and stitch them together so I could iterate over each one and scan a smaller area. I could throw scanning each grid in a queue of delegates and process them in small batches. This sounds like it might work to allow the UI to not hang for so long but I have not tested it yet. I think I read somewhere else that you can only have up to 31 grids though, so not sure if that is the best approach.

I was hoping we could get some sort of guidance or recommended approach for this.

Hi

Right now there isn’t an option for this unfortunately.
I cannot just run it in another thread because most of the graph processing things need access to the Unity API like e.g UnityEngine.Physics.
I have been thinking about refactoring it to instead of calling the grid graph with a delegate to report progress I would call it using an IEnumerator and use a much higher granularity of progress reporting. Then you would be able to use the AstarPath.ScanLoop method to calculate the graphs over several frames.
This is not implemented yet however.

I have tried to follow this and used Scanloop function instead of just Scan.

But I just don’t seem to be able to get the main Unity thread to be unblocked while scan is under progress.

Any ideas?

The Scanloop is implemented right? I saw this in the code, so I tried to use it. But it doesn’t stop from blocking the main thread. (my loading process image does not keep rotating… even one bit)

It’s either I am not using it right or Scanloop isnt working?

I have changed Scan() to :

public void Scan ()
{
OnScanStatus info = delegate(Progress p)
{
};
ScanLoop(info);
}

And then used it like this :

AstarPath.active.Scan();
while (AstarPath.active.isScanning) yield return null;

Aron can you help please? Thanks!

See AstarPath.Scan over multiple frames