- Home /
NavMeshAgent SetDestination too slow
Using SetDestination, my NavMeshAgents will usually find a path (or fail to do so) within a few frames. However, they often lag on the order of up to several seconds before finding a path, which is unacceptable. Interestingly, this can even happen when the destination is nearby and within the agent's line of sight.
So, fellow Unity Nav system victims, what do you do here? Is there any way to enforce a maximum frame limit for SetDestination? Do you go all the way to using CalculatePath to get a result immediately and spike the CPU for that frame? Creative solutions in between?
Answer by insominx · Oct 11, 2015 at 05:10 PM
I'm unaware of any way to control the lag of SetDestination other than possibly setting the value of NavMesh.pathfindingIterationsPerFrame but YMMV.
The only completely deterministic (predictable number of frames) solution is to use CalculatePath/SetPath (on demand same frame).
One method I've used with pathing groups of agents is to compute the full path to the destination only once and then have each group member calculate nearby paths based on that. If you can get away with only paying the full cost once per group, you're far less likely to have performance problems.