So I’m trying to create a simple turn based Xcom Style movement grid, I’ve found a list of nodes in a bounds area and used ABPath.Construct to create a path to each node it found. Problem is the paths returned have a node count of 0. I’m assuming it’s because I’m trying to read the path before it’s calculated but I’m not sure how to write the OnPathDelegate callback and if I use BlockUntilCalculated I get a “The specified path has not been started yet.” Error. Here is my code.
void CreateMovementGrid(Unit unit)
{
GridGraph graph = AstarPath.active.graphs[0] as GridGraph;
bounds.center = unit.transform.position;
bounds.size = new Vector3(25, 10, 25);
List<GraphNode> nodes = graph.GetNodesInRegion(bounds);
List<ABPath> paths = new List<ABPath>();
for (int i = 0; i < nodes.Count; i++)
{
if (nodes[i].Walkable)
{
//Debug.DrawLine((Vector3)nodes[i].position, (Vector3)nodes[i].position + (Vector3.up), Color.black, 50);
var p = ABPath.Construct(unit.transform.position, (Vector3)nodes[i].position);
p.BlockUntilCalculated();
paths.Add(p);
}
}
}
public void PathCalculated()
{
}