Change Width and Depth repeatedly at runtime?

Is it possible to change the number of nodes, that is “Width(nodes)” and “Depth(nodes)” at runtime?

I saw one question about this on the forum, but I wasn’t clear about what the response meant. So I’ll explain what I’m doing.

I’m using AP pro to find paths on a 2D grid set up using Rotorz tile system. I created a class derived from GridGraph and a corresponding editor so that it works with the APath inspector. It works beautifully.

I also am periodically changing the tile system by loading a level, let’s say, which can have different dimensions. So I might go from a 50x50 tile system to a 7530 (or whatever) size. Can I change the width/depth in AP or is it better to just set A*P to the maximum possible size (say, 200 * 200) and let the “RotorzGridGraph : GridGraph” class handle this?

Just wanted to see what your opinon is before I start mucking around in the weeds of your code.

Hi

The system can easily handle it if you just set it to the maximum size. But if you want to change the size, here is how you do it.

`
var graph = AstarPath.active.gridGraph;
// Setup a grid graph with some values
graph.width = 50;
graph.depth = 50;
graph.nodeSize = 1;
graph.center = new Vector3 (10,0,0);

// Updates internal size from the above values
gg.UpdateSizeFromWidthDepth();

// Scans all graphs, do not call graph.Scan(), that is an internal method
AstarPath.active.Scan();`

Thanks!

That was a good start but it doesn’t seem to work exactly like that. Here’s what I did (and tested), for clarification in case anyone else needs to do this.

I changed a few variable names so as to make the example below less specific to what I did.

NB - RotorzGridGraph is a class derived from GridGraph which knows how to look for unwalkable areas based on the solid flag and other flags set for each tile. The center point of the grid graph is set to the center point of the tile system (if it’s rectangular). I can post those files too if anyone is interested.

`
int tileSysWidth = aTileSystem.ColumnCount;
int tileSysDepth = aTileSystem.RowCount;
Vector3 center = new Vector3((float)tileSysWidth / 2.0f, -((float)tileSysDepth / 2.0f), 0);

Type RotorzGridGraphType = AstarPath.active.astarData.GetGraphType("RotorzGridGraph");
var graph = AstarPath.active.astarData.FindGraphOfType(RotorzGridGraphType) as RotorzGridGraph;

// Setup a grid graph with some values
graph.width = tileSysWidth;
graph.depth = tileSysDepth;
graph.nodeSize = 1;
graph.center = center;

// Updates internal size from the above values
graph.UpdateSizeFromWidthDepth();

// Scans all graphs, do not call graph.Scan(), that is an internal method
AstarPath.active.Scan();`

If I added some extra complexity here, let me know.