Function RecastGraph.ReplaceTiles

ReplaceTiles (TileMeshes tileMeshes, float yOffset=0)

Load tiles from a TileMeshes object into this graph.

Public
void ReplaceTiles (

TileMeshes

tileMeshes

The tiles to load. They will be loaded into the graph at the TileMeshes.tileRect tile coordinates.

float

yOffset=0

All vertices in the loaded tiles will be moved upwards (or downwards if negative) by this amount.

)

Load tiles from a TileMeshes object into this graph.

This can be used for many things, for example world streaming or placing large prefabs that have been pre-scanned.

The loaded tiles must have the same world-space size as this graph's tiles. The world-space size for a recast graph is given by the cellSize multiplied by tileSizeX (or tileSizeZ).

If the graph is not scanned when this method is called, the graph will be initialized and consist of just the tiles loaded by this call.

// Scans the first 6x6 chunk of tiles of the recast graph (the IntRect uses inclusive coordinates)
var graph = AstarPath.active.data.recastGraph;
var buildSettings = RecastBuilder.BuildTileMeshes(graph, new TileLayout(graph), new IntRect(0, 0, 5, 5));
var disposeArena = new Pathfinding.Jobs.DisposeArena();
var promise = buildSettings.Schedule(disposeArena);

AstarPath.active.AddWorkItem(() => {
// Block until the asynchronous job completes
var result = promise.Complete();
TileMeshes tiles = result.tileMeshes.ToManaged();
// Take the scanned tiles and place them in the graph,
// but not at their original location, but 2 tiles away, rotated 90 degrees.
tiles.tileRect = tiles.tileRect.Offset(new Vector2Int(2, 0));
tiles.Rotate(1);
graph.ReplaceTiles(tiles);

// Dispose unmanaged data
disposeArena.DisposeAll();
result.Dispose();
});