A* Pathfinding Project

Use with existing graph


Hey. My game already has a* but we’ve hit performance and other issues so I’d like to switch over to this.
We already have our own code scanning walkable nodes and making a grid.
Is it possible for me to manually create a grid, set it in your A*, and then simply request paths?




Yes. First take a look at https://arongranberg.com/astar/docs/runtimegraphs.html (or if your graph has a fixed dimensions you can just create it in the unity inspector).
Then you can set the node parameters like

AstarPath.active.AddWorkItem(new AstarWorkItem(ctx => {
    var gg = AstarPath.active.data.gridGraph;
    for (int z = 0; z < gg.depth; z++) {
        for (int x = 0; x < gg.width; x++) {
            var node = gg.GetNode(x, z);
            // This example uses perlin noise to generate the map
            node.Walkable = Mathf.PerlinNoise(x * 0.087f, z * 0.087f) > 0.4f;

    // Recalculate all grid connections
    // This is required because we have updated the walkability of some nodes
    gg.GetNodes(node => gg.CalculateConnections((GridNodeBase)node));

See https://arongranberg.com/astar/docs/graphupdates.html#direct


Thanks for the super quick response.
Went ahead and bought the new version too (thanks for the discount :slight_smile: )

This worked perfectly, and was up an running really quickly.