Advice for Huge Terrain Grid

I’m looking for the best approach to manage a large terrain grid (8x8 tiles, each 1000m²) using A* Pathfinding. Any advice on optimizing performance and accuracy?

I’m using A* PRO to draw some roads and path over the terrain, basically shouldn’t be complex, but the gird that I’m able to achive is 1024*1024 with a cell of 7.8125.

So I’m using AstarPath and when I init the grid I try to get it smaller but didn’t work:

float worldSizeX = _terrainGrid.GetLength(0) * _terrainGrid[0, 0].terrainData.size.x;
float worldSizeZ = _terrainGrid.GetLength(1) * _terrainGrid[0, 0].terrainData.size.z;
float nodeSize = 2; 
int graphWidth = Mathf.RoundToInt(worldSizeX / nodeSize);
int graphDepth = Mathf.RoundToInt(worldSizeZ / nodeSize);

gridGraph.SetDimensions(graphWidth, graphDepth, nodeSize);
gridGraph.center = new Vector3(worldSizeX / 2f, 0, worldSizeZ / 2f);
gridGraph.is2D = false;

Despite explicitly setting float nodeSize = 2; the cell size remains around 7. I checked the calculations, but I can’t figure out why the grid isn’t reflecting the expected resolution. Could it be an internal limitation of A* or something I’m overlooking.

So maybe a better solution could be to create a grid for each terrain tile, isn’t it?
The terrain is procedurally designed, so the roads have to, that’s why I thought A* would be a good solution, but the grid is too big and lack of details, so often fails on founding a valid path.

Maybe adding a RecastNavmeshModifier would improve performance and helps?
I’m quite lost.

Any advice is very welcome :slight_smile:

  • A* version: 5.3.7
  • Unity version: 6000.1.5

Yeah I’d definitely start by switching to a RecastGraph over a GridGraph here. They handle huge areas a lot better. Alternatively, you can also look into the ProceduralGraphMover to make a graph that follows your agent, instead of scanning the entire scene. In your case I’d start with Recast though.

1 Like

ProceduralGraphMover looks exactly what I need, I could use a much more detailed grid!
Thank you, I’ll test it both! :slight_smile:

1 Like

And yes. The grid graph is artificially limited to 1024x1024. Large grids use up a lot of memory, so you pretty much never want anything larger than 1024x1024.

I’m just using it to draw roads and rivers, so a stretched grid at 1024 is still fine, because a single cell is half the width of the road, so I should be fine.:wink:

For the NPC prolly will need something different.

Hello it’s me again, the Pathfind to try to get up on a steep angle start going zig-zag like, which is fine but the bend is very close, so I was wonder if I could tell the to the system to make wider bend, like: “You can’t bend making a 90° corner!”

Hi

There’s no such option for pathfinding. But some movement scripts can smooth the path.

For example the FollowerEntity has an option for “desired distance from walls”, which is very useful in situations like these to make smoother turns.
There’s also the SimpleSmoothModifier which can be used with the AILerp and AIPath movement scripts, though one has to be careful when using it, since it doesn’t take the world geometry into account when smoothing.

1 Like

gridGraph.rules.AddRule(new RuleTurnPenalty...

It might be worth taking into consideration. :smile:
because RuleAnglePenalty I guess is on Y angle, isn’t it?