Hello,
So i have this bit of code where by i place down a section of my map and i want to update that area only for the recast:
public void UpdateGraph(Vector3 size, Vector3 center)
{
AstarPath.active.astarData.recastGraph.forcedBoundsCenter = center;
AstarPath.active.astarData.recastGraph.forcedBoundsSize = size;
AstarPath.active.Scan();
}
But for some reason it will remove all the navmesh that was previously generated outside of the bounds, where as i wanted it to just update the nodes in this area and still keep the rest of the navmesh in the world as i left it. I presume i have done something wrong here? Am i using the wrong methods to update the recast graph in such a way?
I am trying to avoid updating the entire map when i place down a section of the map as it will take ages to calculate and hangs the game.
Hi
That will completely recreate the graph, if you want to recalculate the graph in only a specific region, then use graph updates.
See http://arongranberg.com/astar/docs/graph-updates.php
Note that it will recalculate any tiles the bounds touches, so if your original bounds is exactly the same size as a single tile it might touch the neighbouring tiles (which I don’t think you want), so it might be a good idea to shrink it a tiny bit.
So will it only work if it’s inside the graph’s bounds? I placed a building down in an empty world where by the graph’s initial bounds size is 1f,1f,1f at center 0f,0f,0f and it won’t update floor plan.
How ever, if i set the graph’s bounds to say 100f,1f,100f and place the prefab inside these bounds, then it works fine.
Does that mean i have to expand the graph’s bounds size as the player builds outwards making a bigger and bigger world so that the new prefabs placed down can be included?
Example i placed this outside the graph bounds:
And it doesn’t update then i tried it inside a graph bounds:
Is there a simple way to update the graph’s bounds easily as the player builds based on prefab colliders it seems quite difficult to work out my actual world bounds as the player builds the world in different directions & different sized prefabs or to add to the bounds size as they build.
Hi
Correct, it will update an existing tile. There is unfortunately no way to expand the recast graph to contain an arbitrary position without completely recalculating the graph, however you should be able to make it sufficiently large from the start, with most tiles being completely empty.
Hmm wouldn’t this make procedural generated at run time a problem as i can’t have an infinite sized graph from the start.
Is there no way you can add a feature where by we can increase the size of the recast’s bounds at run time without losing the graph so it simply adds to it or takes away, and then we can also call for Graph Updates which will update the graph in the area specified by the box collider bounds. That way i don’t need to set a huge bounds from the start as i am not sure how that would really work if i have a procedural generated size ?
Hi
Sorry, there is no out of the box way to do that.
It could probably work somehow by moving the graph and then move the tiles to new indices in the recastGraph.tiles array, but there would be some things that would have to be adjusted. For example nodes store the tile index as part of the vertexIndex and the connections to nodes that go out of bounds would have to be removed.