Do I have to optimize path requests myself?

I have a lot of enemies in my levels, up to 100 and they fight against the army of the player which is also up to 50 agents/units. When enemies detect the player or his troops, it takes quite some time until they start moving.

But 90% of the enmies are just standing still (somewhere else on the map) - so why do those paths take so long to calculate? Especially as there is literally a straigt line to walk to the player?

The NavMesh class has some functions like “NavMesh.Raycast” which is quite a fast operation. Do I have to call this myself before even calculating a path so I can just skip the calculation and assign a path with two “corners” to the NavMeshAgent or is the NavMeshSystem smart enough to do this automatically?

Also the other Agents standing somewhere around the map - do they constantly calculate paths to their own position (because SetDestination is called once and AutoRepath is active)? Or is the system smart enough to make a simple “am I already at the destination” check to skip those path-calculations?

It feels like I have to optimize this myself … or could there be any other reason why agents are getting new paths with such a delay? (Delay of up to 2 Seconds)

so, Unity’s NavMesh system isn’t really optimized for large amounts of NPCs and complex pathing. The pathfinding code runs on the main thread so you’re screwed and because Unity has no incentive whatsoever to improve this, you should either use this or go straight for A* Pathfinding.

1 Like

I see, that’s what I thought. Hopefully the A* asset is on sale soon.

Will unity use the RVO2 obstacle avoidance algorithm?
https://gamma.cs.unc.edu/RVO2/