Search Unity

NavMeshAgent Performance Issue

Discussion in 'Navigation' started by FiveFingerStudios, Jan 6, 2018.

  1. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    I'm seeing a huge performance impact when have 30+ NavMeshAgents in a scene. They are moving around fully rigged Humanoid characters with bones.

    When I look in the profiler I see the below process taking up 4 ms of time.

    Components.NavMeshAgent.TransformChangedMessage

    ..which is way too much time as I'm making a VR game. They take up that much processing even when they aren't actively following a path. The only way to prevent it from taking up so much resources is to disable it.

    How do games that have many onscreen fully rigged character move them around with the huge performance impact?
     
  2. Miggi124

    Miggi124

    Joined:
    Jul 31, 2017
    Posts:
    69
    Hi,

    I know that this may not be the exact issue, but calculating a path for all those agents will take some time. Perhaps it would be better to calculate them earlier with the CalculatePath (I think it's called that) function. This might help, as well as looking into optimization.

    - Miggi124
     
  3. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    989
    I've had hundreds of agents pathing and moving around just fine even on a CPU that cost me $50 back in 2009 so I doubt that the path finding is the real culprit.

    I'd say the clue is likely in the text 'TransformChangedMessage'. If you're characters haven't had their hierarchies optimized then they may very likely contain dozen or even hundreds of child objects. Any time the root changes position Unity will recursively inform every single transform in that hierarchy of the change and this can add up pretty quickly.

    Have a look at this blog post about how you might be able to optimize your hierarchy without impacting your workflow too much. https://blogs.unity3d.com/2017/06/2...-the-spotlight-team-optimizing-the-hierarchy/
     
  4. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    Thanks for the link.

    I think I should have mentioned that I’m already using this option.

    I’ve tried both “Optimze GameObject” on the rig import and I’ve tried to just right click the Animator component and choose “Optimize Transform Heirarchy” .

    Optimize GameObject is supposed to be better than Optimize Transform Heirarchy, but I haven’t seen any differences in my tests.
     
  5. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    989
    Hmmm, that is quite odd. If you haven't done so already, try ruling out the navmesh agent by disabling it and using a simple script to move the objects around instead. If that works, you might consider decoupling the pathfinding agent from the actual movement by disabling its ability to directly affect the model's positions and rotation and instead use your own script to move the model based on the agent's desired heading.