A* Pathfinding Project

Dynamically growing grid based on tilemap


#1

Thanks for the fantastic navigation system, I really love it.

I am a novice, and currently trying to something that I don’t get figured out. I would love some guidance.

I start with a small grid (world), and it is possible to expand it ingame. Digging out more rooms.

Currently I am using the tilemap system of Unity and for performance, I thought it might be good to only have the “floor” layer of my tilemap traversable, and the pathfinding system copy the position of the floor tiles. This way, I dont have te generate a 1000 x 1000 grid in Astar, and I dont need colliders on the walls.

For a little more clarity I added a screenshot

The top part of the tiles in the screenshot are added ingame. This is already working. I would like to archive that “new nodes” are placed on the same position as a newly placed “floor tile”.

Is this even possible? Any guidnece to get me started is higly appreciated :slight_smile:

ps. I am currently in testing phase. Later I would like to transform it to a isometric grid.


#2

Hi

The grid graph needs to be an actual grid, it cannot skip nodes here and there. You can technically use a point graph and connect the nodes together with it (see https://arongranberg.com/astar/docs/runtimegraphs.html), but you will loose many optimizations that the grid graph does and it will most likely use more memory anyway (unless you can reduce the number of nodes by maybe a factor of 4 or more).

If you can read the data from the tilemap you can apply that to the grid afterwards though. Take a look at this page for an example: https://arongranberg.com/astar/docs/graph-updates.php#direct


#3

Hey aron,

Thank you so much for your reply, and for the tilemap tip.
Is it possible to let the grid “grow” (the width and height of the overall grid) if the tilemap grows?

If that’s not possible, maybe it’s the best solution to create a bigger grid at the start, and fill in “walkable” tiles if the tilemap grows (rooms a dug out). It wasn’t my intention to make maps unlimited size anyway.


#4

Hi

You can change the size of the grid graph at runtime, however then you will need to recalculate the whole graph and not just the new part.
See https://arongranberg.com/astar/docs/gridgraph.html#SetDimensions