So i start the game with an empty world as intended. But the code simply errors straight away:
DivideByZeroException: Division by zero
Pathfinding.RecastGraph.ScanAllTiles (.OnScanStatus statusCallback) (at Assets/AstarPathfindingProject/Generators/RecastGenerator.cs:1115)
I have scan on Awake encase the world isn’t empty to start with - it varies. But i am pretty sure it should not error but simply not create a graph…
I’m not using tiles for my Recast graph if that makes much difference… using tiles how ever does stop the error so its something to do with not using tiles
Hi
That sounds bad.
Scanning an empty graph works perfectly fine for me, so maybe it is something I have fixed in a dev version.
Can you check what code is at that line? (the line numbers differ between versions, so it is hard to know which line you mean).
@aron_granberg
Hey the error occurs in
Script:
ReCastGenerator.cs
Method:
protected void ScanAllTiles (OnScanStatus statusCallback) {
Line:
//Number of tiles
int tw = (gw + tileSizeX-1) / tileSizeX; // here
If it helps, i request to re-scan the world using these 3 lines:
void Start(){
AstarPath.active.astarData.recastGraph.forcedBoundsSize = worldSize;
AstarPath.active.astarData.recastGraph.SnapForceBoundsToScene();
AstarPath.active.Scan();
}
I also get this warning prior to the error:
No MeshFilters were found contained in the layers specified by the 'mask' variables
But the mesh filter warning is to be expected given the world is empty at Start.
Ok, seems like the bounds set for your graph might have been smaller than a single voxel.
I have fixed this in my dev version now, thanks for reporting the bug.
I’m not sure if i misunderstand but my default bounds are pretty large before the game starts. Here is my settings perhaps there something i have set that might highlight the problem.
When will the dev version be released as i can’t compile my game at the moment due to this error.
Hi
You are using
AstarPath.active.astarData.recastGraph.SnapForceBoundsToScene();
Since there is nothing in the scene, I suspect that will set the bounds to have a zero size. Make sure it has a non-zero size (at least as large as a voxel or two) to work around the issue.
Okay yeah that solved it thanks !
If i am manually setting an area for the Recast like this:
AstarPath.active.astarData.recastGraph.forcedBoundsCenter = new Vector3(0f, 0f, 0f);
AstarPath.active.astarData.recastGraph.forcedBoundsSize = new Vector3(10f, 0f, 10f);
AstarPath.active.astarData.recastGraph.SnapForceBoundsToScene(); //is this needed?
AstarPath.active.Scan();
Is the snap force method still required here? As i’m unclear what the method does the documentation doesn’t have a description for it.
It seems to work without the method just wanted to make sure.
Hi
TL;DR, no you should not call it.
Ah, it does indeed seem like that method does not have any documentation. I have added some in my local dev version.
/** Changes the bounds of the graph to precisely encapsulate all objects in the scene that can be included in the scanning process based on the settings.
* Which objects are used depends on the settings. If an object would have affected the graph with the current settings if it would have
* been inside the bounds of the graph, it will be detected and the bounds will be expanded to contain that object.
* For example if #rasterizeMeshes is set to true, the bounds will be changed to contain all meshes which are in a
* layer included in the #mask or in the #tagMask or have a RecastMeshObj component attached to the same GameObject.
*
* This method corresponds to the 'Snap bounds to scene' button in the inspector.
*
* \see rasterizeMeshes
* \see rasterizeTerrain
* \see rasterizeColliders
* \see mask
* \see tagMask
*
* \see forcedBoundsCenter
* \see forcedBoundsSize
*/
Ah okay thanks good to know Everything is working again now.
1 Like