Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Limitations using Navigation for large crowds (over hundreds of agents)

Discussion in 'Navigation' started by bigoMay, Mar 2, 2016.

  1. bigoMay


    Sep 14, 2013

    I am currently developing a crowd simulation in Unity 5.3 using the navigation system provided by the game engine, but I am running across some limitations when the number of agents gets large (over several hundreds).

    In my algorithm there is a continuous spawning of navigation agents (around 3 per second). When a new navigation agent is spawned, it will decide on a destination point to go and it will start walking. Along its way, certain events can make the agent change its destination point, being force to recalculate its path in the navigation system. Each time this situation happens, the method SetNewDestination is called:

    Code (CSharp):
    1. NavMeshAgent navAgent = gameObject.GetComponent<NavMeshAgent>();
    3. SetNewDestination(Vector3 newDestination)
    4. {
    5.     navAgent.ResetPath();
    6.     navAgent.SetDestination(newDestination);
    7. }
    This works fine up to two or three hundred agents, but the problem comes when the number of agent reaches limits over four or five hundred. When the latter occurs, every time an agent wants to change its path it gets stuck on its position, and it takes a very long time until it calculates the new path. It seems to me that the navigation system gets overloaded and it cannot handle all the path calculations that need to be done every second (both for new agents and for those that are changing the path).

    Am I missing anything from the navigation system that I am not using? How far can the navigation system go on large crowd simulations? I will appreciate any thought you can throw about it.

    Thank you!

  2. laurentlavigne


    Aug 16, 2012
    Stagger calls to SetNewDestination, also increase pathfindingIterationsPerFrame and if the agents are very close together decrease avoidancePredictionTime
  3. bigoMay


    Sep 14, 2013
    Thank you for the response.

    I increased the limits of pathfindingIterationsPerFrame and decreased avoidancePredictionTime and now the performance is much better. I see that the first one increases the use of cpu, so I am trying to tune it to an optimal value. It seems to work well for 5000 (so far, I am not using much cpu for other things, so I am giving more room to the navigation system).
  4. JBR-games


    Sep 26, 2012

    Have a look at this.
    script calling navmesh calculate path integration without use of a nav mesh agent as an LOD level and integration with unitys culling groups
    Athomield3D and pixxelbob like this.
  5. pixxelbob


    Aug 26, 2014
    @JBR games that looks excellent. I'm definitely going to go down that route with my upcoming project.Hopefully I can piece it together. Thanks for sharing!