Runtime "Snap bounds to scene" when using Recast

Hi

Is there a way I could use the function “RecastGenerator.SnapForceBoundsToScene ();”? I need this because my levels greatly vary. Some are quite big and some are really small. So instead of having a box that is 200x40x200 and try and scan that everytime a level generates it could be much smaller and therefor not spending as much time. I tried this while in the editor and this is the result I got.
With a 200x40x200 box, when the level first generated and then scanned, it took around 100 ms. Now when I snapped it down to what the actual size is of one of the smallest levels (12x≈1.4x30), it took 13 ms. That is quite the difference.

But how can I access that function from a script? I can not find a way to do it. If it is not possible, please add a way to use it a bit easier.

Thanks

Hi

Sure

var graph = AstarPath.active.astarData.recastGraph;
graph.SnapForceBoundsToScene();
// Recalculate the graph
AstarPath.active.Scan();

Note however that this will only encapsulate the bounds that touches or are inside the existing bounds (so usually it only shrinks it). So you might want to reset the forcedBoundsSize field before doing this to make sure that after you have played a small level it can be enlarged to a cover a large level.

1 Like

Thank you so much!

I simply just added this after the map has been built.

AstarPath.active.astarData.recastGraph.forcedBoundsSize = new Vector3(200, 40, 200);
AstarPath.active.astarData.recastGraph.SnapForceBoundsToScene();
AstarPath.active.Scan();