Tiniest framerate hitch after ScanAsync

  • A* version: [5.3.7pro]
  • Unity version: [2022.3.52f1]
    Hello,
    Love the product - have a question about ScanAsync regarding a small framerate hitch - tried searching the forums and didn’t see anything on this, so if there are already solves to it posted, please point me that direction.

My playable area is very large so I just started using the ScanAsync so I could update the grids on the fly - centered near the player. Right now updating as the player gets about halfway from the center to the edge of the grid.
I’m still working out if this is the best way to handle a large playable area or to try to encompass a much larger area to do the updates less frequently.
I am using two overlapping grids (for different AI types) that are 500 by 500 with a 25 unit node distance.
When I do the ScanAsync , I am getting the tiniest of hitches at the end of the sync. Happens on PC and iOS.
I tried doing the syncs for both on the same call. I tried doing them sequentially as well. I also just tried only updating one to see if it was the two grids causing the issue.
Is this the expected behavior?
EDIT: as I am still in the initial stages of working this out, there is a chance that I have triggered a new scanasync prior to the last one finishing sometimes - not sure if that would change things.

Thanks!

Code being implemented in the ScanAsync:
At the call:
print(“ASYNC SCAN OF ASTARS … starting…”);
StartCoroutine(ASyncGridScans());

Then:
IEnumerator ASyncGridScans() {
foreach (Progress progress in AstarPath.active.ScanAsync()) {
//Debug.Log("Scanning… " + progress.ToString());
yield return null;
}
print(“ASYNC SCAN OF ASTARS… COMPLETE!”);
}

ScanAsync doesn’t guarantee a good frame rate. If you are seeing a hitch at the end of the scan, that is likely when it needs to apply the update in a single step, to make it visible to the rest of the game. You can use the unity profiler to figure out more exactly what is causing the hitch. I would also recommend that you disable “Show Graphs”, as updating the rendered gizmos can be slow.

It sounds like you are moving the graph to follow the player, is that right? If so, I would recommend using the built-in component for this use case: the ProceduralGraphMover.
See Large worlds - A* Pathfinding Project

The code will log a warning message if this happens. Doing so will block until the previous async scan has completed, which can definitely cause a frame rate hitch.

1 Like

Thanks for the super quick response and suggestions!

The ProceduralGraphMover worked wonderfully on PC and then on iOS after a few tweaks. And no perceivable hitches.

Really appreciate the support.

1 Like