Make A* use an existing grid

Ok, let me explain in detail.

I am doing a 2D game and the player can move on a grid. Now my “boss” wants me to add enemies that follow the player on the grid.I Was going to build my own A* from scratch (can’t really bother) so If there is any way to initialize and use A*project with an existing grid how could I do that? And I use my own character controller as the player moves on a fixed time between nodes.

I tried going through the scripts and figure it out for myself, but I guess it takes less time to ask :stuck_out_tongue:

Thank you in advance,


Is your grid uniform or non-uniform? You can do both, but uniform grids are quite a lot easier.

The grid is uniform. I just need to know how to set a Grid to A* and then when calculating a path I need to get the node List (aka Path) to move the AI following my logic.


AstarPath.RegisterSafeUpdate (delegate () {
// Get the grid graph
var gg =;

for ( int z = 0; z < gg.depth; z++ ) {
for ( int x = 0; x < gg.width; x++ ) {
gg.nodes[z*gg.width + x].Walkable = true;
// Make sure the above callback is run directly ();

That code above will set all nodes in the grid graph to walkable. You can modify it to get the data from your code.

The wrapping in a RegisterSafeUpdate call is necessary to prevent horrible issues when using multithreading (modifying the graph while pathfinding is calculating a path on it is not a good idea).

You can take a look at the get started guide to learn how to write a movement script

Thank you a lot, I already had the pleasure to work with your system, and now I wanted to use it for some games with my new employment.