Custom Walkable property and Multiple Grid Graphs

I am working on a 2D game (similar RimWorld or Crashlands). The map is split into ‘chunks’, which contains tiles that store info about walkability and penalties. Is there a way that I can tie a Grid Graph node to one of my own tiles so I can tell it to check my own IsWalkable property? Can this be done via inheritance or some other way? I’m not currently using colliders for a lot of things since there could potentially be tens of thousands of colliders, and some ground can’t be walked on and wouldn’t have a collider anyways (ie, deep water).

On a similar note, how large of a grid graph can this project handle? My assumption is large maps need to be split into multiple graphs to keep pathfinding times short. If so, is there a way to find a path across multiple grids?

Thanks!!

I did some testing last night and did the following:
I had my Chunk class inherit from GridGraph.
I had my MapTile class inherit from GridNode.

I think this will work, however I was getting errors when trying to create the graph and the nodes. I don’t have the code in front of me now, but it complained about initializing nodes outside an update, so I found that it should be inside a AddWorkItem block, so I did that. However after that I got a different error about doing things recursively and not to wait for code to finish.

Are there any examples of how to instantiate/add a grid graph and it’s nodes programmatically?

Thanks!

Hi

The easiest way is to subclass the GridGraph class and then override just a single method, the UpdateNodePositionCollision method.

public override UpdateNodePositionCollision (GridNode node, int x, int z, bool resetPenalty = true) {
      node.Walkable = DoSomeWorkHere();
      // Store walkability before erosion is applied
      // Used for graph updates
      node.WalkableErosion = node.Walkable;
}

Doing this will make it work out of the box with graph updates as well. So if your world has changed you can issue a graph update around those bounds and it will call the UpdateNodePositionCollision method again. It will even with with the ProceduralGridMover script.

The system can handle grid graphs up to 1000*1000 (then it has been artificially limited, it can technically support larger graphs). However beware of the memory usage which can be quite significant for a graph of that size.
I recommend that you only use a single graph, but if necessary you can move it and rebuilt it in a new position.