- A* version: 5.2.5
- Unity version: 2022.3.23
Hello!
I am looking for a way to be notified when a Path
calculation fails, so that I can handle it as I need (try again, change destination, teleport, …):
pseudo-code:
IAstarAI ai;
ai.destination = Vector3.one;
// Some frames later
if (ai.path.CompletedState == Error) {
// Do something depending on game logic. Don't try to recalculate path again and again as it has a very high probability of failing again
// Ideally know the error type (canceled, cannot find end, unreachable, ...)
}
Is there a way to do that without having to create and handle Path
manually. I’d rather not lose the functionalities provided by Seeker
// FollowerEntity
out of the box.
Thank you!
You can use Path.error
for this There’s also Path.errorLog
to know what the error was
But how can I get the current Path from an IAstarAI?
It sounds like you’re not using Seeker, based on the " I’d rather not lose the functionalities provided by Seeker
// FollowerEntity
out of the box." line. I dug around but I don’t see how IAstarAI
holds its path, but you have the option to create a path, then assign it to the interface yourself. Here’s a quick example of what I got working:
ABPath newPath = new(){
startPoint = transform.position,
endPoint = Vector3.zero // Destination. I just made them all go to the origin
};
ai.SetPath(newPath);
ai.SearchPath();
There you’d have access to the path itself where you can check it where you’d need. There’s other options too, though.