Search Unity

Question NavMeshAgents get stuck to corner of NavMeshSurface after other AI are destroyed

Discussion in 'Navigation' started by GamingParade, Mar 22, 2022.

  1. GamingParade

    GamingParade

    Joined:
    Sep 16, 2018
    Posts:
    1
    I'm having some interesting behaviour with NavMeshAgents. So I've been working on a project for the past few months which is revolving around creating believable enemy AI systems for stealth games. When the player kills an enemy they can pickup the body and put it into a body bag, this all worked well and fine for a while but now once the player has picked up two corpses all Nav Agents do this.
    upload_2022-3-22_22-24-22.png
    They are still in their patrol state (using a behaviour tree) and all of the AI have a destination set which can be seen on the debug tools for the Agent. However if I try to move the AI whether that being dragging them around or setting a position through the inspector they will snap back to a corner of the NavMeshSurface.

    Using Unity 2021.1.17f1 and using the latest compatible version of the NavMeshComponents package provided by Unity.

    Things I've tried:

    • Changing Radius and Height of agents
    • Setting the floor and such as navigation static objects
    • Removing the NavMeshComponents package scripts and replacing them with the original NavMesh system. Didn't work and took a lot longer to build the NavMesh
    Interesting behaviour:

    • The amount of body bags the player has to pick up seems to be related to how many AI are in the scene. For example currently there are 23 AI and it takes two body bags for this glitch to happen, but if there are 24 to 31 AI in the scene then it requires three body bags to be picked up for it to happen.
    All calls to the NavMeshAgent are done through a AILocomotion script which handles enabling and disabling rotation, movement and updating the animation. Movement is only disabled upon death or when the AI is in the wait state, other than that every Move based state re-eneables movement.

    Picking up a bodybag has the following code
    Code (CSharp):
    1.                         if (!_carryingBodybag)
    2.                         {
    3.                             SetCarryingBodybag(true); //enables a bodybag mesh attached to the players back
    4.  
    5.                             Destroy(_nearbyAgent.gameObject);
    6.                             _nearbyAgent = null;
    7.  
    8.                             stateChanged = true; //Used for handling UI prompts
    9.                         }