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.