2D grid graph only on some parts

Hello, it s very long i didn t come back here :slight_smile:

Today my question is about how to implement a graph in 2D only on some path i decided to.
Normally, in the examples, it s the contrary, you put obstacles
For me everything is an obstacle, except where i want the AI to be able to walk in
So i found a solution using my tiles with a layer, using them as an obstacle first, and then updating all nodes by telling that s the contrary.
It works but i was wandering if there is an other solution where i could put directly where i want the graph to work only

here is my code

AstarPath.active.AddWorkItem(new AstarWorkItem(ctx =>
var gg = AstarPath.active.data.gridGraph;
for (var y = 0; y < gg.Depth; y++)
for (var x = 0; x < gg.Width; x++)
var node = gg.GetNode(x, y);
node.Walkable = !node.Walkable;
gg.GetNodes(node => gg.CalculateConnections((GridNodeBase)node));

thanks for your time


There’s no built-in solution for this, I’m afraid. So using a solution like that is the best at the moment.
In the beta, you could alternatively write a GridGraphRule, which would make it work automagically with graph updates and other things.
See Grid Graph Rules - A* Pathfinding Project