Search code examples
c#unity-game-enginenavigationagent-based-modelingnavmesh

Unity Navmesh Performance Issue


I am currently working on a fire evacuation project using Unity Engine navmesh component. However, when I increase the number of agents, the performance of evacuation decreases significantly. Some agents are waiting very long time to evacuate. Do you know how can I solve this navmesh agent performance issue ?

Evacuation Script


Solution

  • Move your SetDestination to Start().

    public Transform hedef;
    NavMeshAgent agent;
    
    void Start()
    {
        agent = GetComponent<NavMeshAgent>();
        agent.SetDestination(hedef.position);
    }
    

    Based on the NavMesh docs, you are updating and recreating the agent's path every frame. I do not see a reason to do this unless your hedef position changes, which from what I can tell from your use case, it should not. If it does happen to change, then gradually ping units that the position has changed, so you do not have any stuttering when Unity recalculates their pathing.