Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

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

  1. bigoMay

    bigoMay

    Joined:
    Sep 14, 2013
    Posts:
    6
    Hello,

    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>();
    2.  
    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!

    Bigo
     
  2. laurentlavigne

    laurentlavigne

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

    bigoMay

    Joined:
    Sep 14, 2013
    Posts:
    6
    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

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    708
    http://forum.unity3d.com/posts/2457252/

    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

    pixxelbob

    Joined:
    Aug 26, 2014
    Posts:
    111
    @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!