Realistic Limits of PathfindingService

I am asking about the performance of PathfindingService. If I had a large game map, and I wanted there to be hundreds of agents, some operating under groups and some independently, how performant would this be? Does anyone have some examples that they know of to show how performant PathfindingService is?

1 Like

A few tips for optimizing pathfinding that I’ve tested. I don’t have any concrete examples at the moment, but pathfinding in general is pretty expensive. It is no different than other game engines. You can reduce performance by having preset pathfinding nodes if you need to generate a path extremely frequently (but that seems more like a bad code practice than an actual need). It is a good idea to limit the amount of pathfinding logic to at least a few seconds between searches.

RTS games usually do pathfinding on a group of enemies instead of individually, so everyone in there can go to the same place. If you have individual enemies, before the AI generates a path, they should search around them to see if there are any friendly AI’s near them and check if they have their own generated path. If they do, it can borrow theirs instead of generating its own and add any new points manually as needed.

You can also avoid pathfinding altogether if you do a raycast between the AI and the target. If they are within sight and relatively same height, the AI can just make a beeline towards them. This makes your AI a lot more optimized, and it allows it to pathfind whenever it actually needs to.

tl;dr, you can pathfind for many AIs with relatively light performance costs as long as you don’t use it frequently. Take shortcuts whenever you can.