PointGraph for randomly generated map

Hi, I’m developing an RTS game where a random map is generated from tiles at game start. I have a Map class which creates a rect of 32x32 tiles (it’s actually a hex grid but I represent it as a 2-dimensional array).
Now I am trying to connect a PointGraph to it. Is it at all possible to make this programmatically? Since the map is generated in runtime, i can’t pre-generate the AstarPath in the editor.

What I’m trying to do is (in Map script):

GameObject astarObj = new GameObject(“AstarPath”);
astarObj.transform.parent = this.transform;
AstarPath astar = astarObj.AddComponent< AstarPath >();
Pathfinding.PointGraph graph = astar.astarData.AddGraph(typeof (Pathfinding.PointGraph)) as Pathfinding.PointGraph;

which is wrong because in AstarPath’s Awake method a lot of initialization happens before I even add the PointGraph.

Some of my tiles are in “water” layer which is non-walkable and some in “ground” layer which is walkable.

I would recommend writing a custom graph generator for this. There is a nice tutorial about it in the docs: http://arongranberg.com/astar/docs/writing-graph-generators.php

You could also do it with a point graph, but it would be slightly hackish. I say you can just copy the source for the point graph and then change whatever you need changing in it to get it to work good with your code.
You should make sure Scan on Awake is not checked in A* Inspector -> Settings. And after you have set up your custom point graph, you can call AstarPath.active.Scan () to scan the graphs.

Did you get this solved? I am not sure if you are looking for a HexGrid, but I have one that works with A*Pathfinding with all the features that GridGraph has. Feel free to email me if you need the code. (afaulds@trinnovations.com)