Hi,
In my game I have several characters which can have assigned some tasks in a sandbox world. In order to check if the character can perform the given task (before assigning it), I want to check if there exists a path between the character and the destination.
I tried to do this like this:
ABPath.Construct(npcLocation, destination, o => pathFound = !o.error);
unfortunately the callback seems not to be called in ABPath.
Is there a better (working) way to check if a certain location can be reached?
Hi
ABPath.Construct will only create the path object, it is not calculated yet.
See https://arongranberg.com/astar/docs/callingpathfinding.html
You can use PathUtilities.IsPathPossible to check if a location can be reached:
https://arongranberg.com/astar/docs/pathutilities.html#IsPathPossible
Thank you for clarification.
I would like to point out that I think it is not a good design to pass a callback to a method although the callback is not invoked through that method.
Better design would be:
var path = ABPath.Construct(start, end);
path.PathCalculatedCallback += MyMethod;
because here you do not expect that the callback is already invoked inside the method.