I am attemping to compute a path between two nodes in a PointGraph I computed in run-time (which I need to do because maps are random).
I have start and end positions as Int3, the exactly values I used to create the PointGraph initially. I am able to find the nearest nodes to both and they are correct. When I ask for the path, though, the path fails with errorLog “Searched whole area but could not find target”
Here is the code in my “Move” method:
// These are Int3 coordinates I used to create the nodes and connections originally
var startPosition = (Vector3) Tile.coordinates;
var endPosition = (Vector3) DestinationTile.coordinates;
// This shows that it can find the correct nodes in the graph
Debug.Log("Goto from " + startPosition + " to " + endPosition);
Debug.Log("Nearest node to startPosition = " + AstarPath.active.GetNearest(startPosition).node.position );
Debug.Log("Nearest node to endPosition = " + AstarPath.active.GetNearest(endPosition).node.position );
// Methods to call when complete
var pathDelegates = new OnPathDelegate(path =>
{
if (path.error) { OnPathFailed(path); } // it always goes here because path fails
else { OnPathSuccess(path); }
});
// Construct the ABPath
var pathDesign = ABPath.Construct(startPosition,endPosition, pathDelegates);
// I also get same error when constructing the path this way
// var pathDesign = ABPath.Construct(AstarPath.active.GetNearest(startPosition).node.position,AstarPath.active.GetNearest(endPosition).node.position, pathDelegates);
// Start finding
AstarPath.StartPath(pathDesign);