Creating a Recast Graph Tile by Tile

So I have made progress on my previous problem. What I’ve done is set up a recast graph that encompasses the entire area, but made it empty upon starting up. From there I am having it update the tiles that the actors are in or adjacent to. The idea was to make it build the graph as the actors needed it, and leave that tile data there once in place so it won’t have to be updated again in the future. Since the graph is a fixed size, as well as being a recast graph, space won’t be an issue. So I had a few questions while I was implementing this:

  1. Is there a way to only update a given tile? (i.e. Tile (23, 78) with a tile grid of 100x100)

  2. I was thinking of having a 2 dimensional array of booleans to check if a tile had been updated yet, since each tile only needs to be updated once. Was their anything built in that serves a similar purpose or should I go ahead with this plan?

  3. When only updating one tile, would the amount of tiles already updated affect how long the new tile would take to update?

  4. While one tile is updating, does that stop all pathfinding on the entire grid from taking place? If so, is their a way around that?

  5. Is there already built in functionality for something similar to this?

Thanks for all your help so far, really glad I bought this :slight_smile:

EDIT: Now that I look around more on the forums I see mention of a tiled recast graph, so maybe there is more support for this method than I realize. I added question number 5.

Hi

  1. You can use a regular graph update (see http://arongranberg.com/astar/docs/graph-updates.php) with updatePhysics=true to make a recast graph recalculate a particular tile (or a group of tiles).

You can make the graph completely empty when you first scan it by making sure that the graph.scanEmptyGraph field is set to true when the scan is done. That will fill the recast graph with empty tiles which you can recalculate later.

  1. No, there is nothing built in for that purpose.

  2. Not significantly, I would expect >95% of the time to be spent in code which is independent of how many other tiles have been recalculated.

  3. Yes, it stops all pathfinding. Right now there is no way around it, it would in theory be possible to allow pathfinding to continue running during most of the update. Graph updates currently guarantee that if a graph update is requested, any path requests made after that will always use the updated graph information (unless graph update throttling is enabled of course). The graph update will however run in a separate thread if multithreading is enabled.

  4. Sorry, no.

Is having updatePhysics set to true the default when updating a graph?

And how does this function look, with nodeSize being a Vector2 representing the number of tiles in a graph, is there anywhere I could improve? It is basically doing a graph update with the bounds being a 1x1x1 box in the center of the tile.

public void BuildTile(IntVector2 tile)
{
if (tile.x >= 0 && tile.y >= 0 && tile.x < nodeSize.x && tile.y < nodeSize.y)
{
if (isBuilt[tile.x, tile.y] == false)
{
isBuilt[tile.x, tile.y] = true;
AstarPath.active.UpdateGraphs(new Bounds(new Vector3(tile.x * tileSize + tileSize / 2f - (tileSize * nodeSize.x) / 2f, 0f,
tile.y * tileSize + tileSize / 2f - (tileSize * nodeSize.y) / 2f), Vector3.one));
}
}
}

Hi

You can get the bounds for a particular tile using RecastGraph.GetTileBounds(x,y).
You might want to shrink those bounds by a small amount however since those bounds will touch the neighbouring tiles.

Maybe something like

var bounds = recastGraph.GetTileBounds(5,7);
bounds.size = Vector3.one;

Update physics is the default, yes.