Custom grid graph - how to?

Hi there! I’m familiar with A* Pathfinding Project, but used it based on the scene geometry before.

For the new project, I need pathfinding in a 2D grid where I can set/modify obstacles manually. So, basically I need a simple grid graph with a method for setting each node to be walkable/not-walkable. No scanning of a geometry and using colliders needed. Just a simple 2D grid.

Did find TextureData, but it seems to be too complex for my needs.

What shall I do? Override GridGraph with my own code? Is there any example of that? What methods I need to override?

PS: I’m a Pro version user.

PS: started to digging to textureData

Hi

You can either override the GridGraph, or you can change the data after it has been scanned, both are relatively easy.

Here is how you can modify the data:

// Make sure pathfinding is not running at the same time
AstarPath.RegisterSafeUpdate(() => {
    var gg = AstarPath.active.astarData.gridGraph;
    for (int z = 0; z < gg.depth; z++) {
        for (int x = 0; x < gg.width; x++) {
            var node = gg.nodes[z*gg.width + x];
            node.Walkable = Random.value > 0.5f;
        }
    }

    // Update connections of all nodes (needs to be done *after* all nodes have been updated)
    for (int z = 0; z < gg.depth; z++) {
        for (int x = 0; x < gg.width; x++) {
            var node = gg.nodes[z*gg.width + x];
            gg.CalculateConnections(x, z, node);
        }
    }

    // Refresh internal pathfinding data
    AstarPath.active.FloodFill();
}

Or you can override the grid graph. With this setup, graph updates will also work out of the box.
See Derive editor from GridGaphEditor?
or Using gridgraph like a tilemap
or Ability to customize collision check

Thank you very much! Because I started digging the TextureData and stuck there with no docs/examples.

Thank you again!