Entities Twitching when number of paths or path length gets too high

When I select 50 units and tell them to move, They spend a second or so moving back and forth (from their start position to a seemingly arbitrary adjacent node) before all falling in line and following the path. If I select 200, they spend about three minutes doing this twitching. Additionally, If I select 10, and tell them to walk from one end of the map to the other, twitching happens. My best guess is that this is an algorithmic complexity Issue, But I am wondering what exactly is causing this behavior and if there is a fix, or a lightweight/ implied pathing way to implement mass unit pathfinding. I could just make the selection group have a “leader” and then have the leader pathfind, and everyone else just follow the leader, But I do not want to do that until I am sure that the problem is what I think it is.

UPDATE: Assigning a leader would not work, because that relies on the (incorrect) assumption that all the units selected will always be in a group.

Hi

So this is a common problem when the pathfinding system is overloaded. What happens is that one of your agents is moving along a path and then requests a new path. When the path is finally calculated the agent may have moved far away from the original point where it requested the path, so it will try to move back to the start of it. This results in the behaviour you see. The built-in AIPath movement script has some code to reduce the risk of this happening. Since you have your own ECS movement script this is code is not used. What it does is to do a simulated movement from the point where it requested the path to the point where it got the path result to see if it should mark any waypoints are already visited.

Check your A* Inspector -> Settings -> Threads setting. If you have 50 agents you should probably use multithreading, depending on your graph size you might want to use more than one thread.

Gotcha. I do not have the pro version, so multi threading is not viable at this time. Additionally, The amount of active agents will be in the low thousands, so while multi threading will be necessary, I believe it alone will not suffice. I would like to figure out how to implement an A* solution that will work for a couple hundred agents on a single thread, then multithread that solution. So aside from increasing the threadcount, do you have any other suggestions, theories, or general ideas about how to do pathfinding on that scale? I’ll try to implement the simulated movement that the built in AIPath has.

Hi

There is a page about general optimizations here: https://arongranberg.com/astar/docs/optimization.html. Some of those tips might be applicable.