Reset a pathfinding AI

So, I feel like this would have been asked before but I couldn’t find an answer to this question so i’m making a post.

I did look at this post: http://forum.arongranberg.com/t/how-to-stop-a-path-prematurely/1321 but it didn’t provide me with the solution that I required.

Quick rundown of what i’m doing.
I have about 100 units that all need to move to the same general area, however, because doing 100 pathfinds to the same approximate area is expensive, I am only getting the closest of the units to do the pathfind and then the remainder of the units follow using basic flocking AI. If a new path is given to the units then the system will find the closest of the units, assign it as the pathfinder, and then the remainder of the units should flock around it, but the previous pathfinding unit maintains its path and tries to obey the path and the flocking AI which just results in it getting stuck in one place.

So, my question is, is there any way to reset an AI to what it is when it first spawns: No path, No Destination?

Hi

Currently the easiest way is to call ai.enabled = false, ai.enabled = true. In future versions it will also be possible to set ai.SetPath(null) to clear the path (right now it throws an exception unfortunately).

I think your case could be solved in another way though. There is a special path type called the FloodPath. You start it at some destination, and after that you can use the FloodPathTracer path to calculate paths to that destination incredibly quickly (maybe 100x faster or something like that).

If this would not work for you, then you could also check out https://arongranberg.com/astar/docs/heuristicopt.html which can improve the pathfinding performance on static maps with lots of obstacles by a factor of 10 easily.

Thanks, i’ll look into the flood paths but at the moment i’m only using the free version so there aren’t any paths built in. I’m just using the free version for my prototype before I invest money. I managed to get it working by writing a custom cancel path function into the AIPath class, but I’ll definitely use your suggestion once I’ve finished my prototype.

Thank you for your assistance.

1 Like