Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

NavMesh creates weird pathfinding graph

Discussion in 'Scripting' started by xCeas, Jun 28, 2020.

  1. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    40
    Hello all,

    I've recently deployed my code, to a new scene where there are some art assets, more detailed terrain (a hill)
    and tried to test the code in a "real" scene.
    I'm currently stuck on pathfinding - I used unity's NavMesh library, baked the terrain and began with testing the scene. It seems that the AI can be 5 meters away from it's target and yet the NavMeshAgent generates a graph which makes no sense, the first node being 300 meters away from where the agent currently is, furthermore the graph doesn't seem to realize there are objects in it's way.

    I will also mention that the only thing that there is between the agent and it's destination is a slight terrain slope.

    Could you guys help me?
     
  2. Zer0Cool

    Zer0Cool

    Joined:
    Oct 24, 2014
    Posts:
    141
    There a much settings in the navmesh generation to do, so its hard to say whats wrong. Perhaps show generated nav mesh graph here (in special the section that isnt working) and the nav mesh generator settings.

    Additionally you must mark objects in the scene as "Navigation Static" to be included in the nav mesh (or the agent dont care about these objects). Also the settings of the agent must fit.
     
  3. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    40
    Thanks for replying,

    Well my scene was baked with default parameters, later I increased the max slope to be very high (almost max), and then I tested it on flat terrain - in all 3 cases the issue reproduced, it seems as if the agent is keen on moving on an impossible path, which it's first point is very far from the agent's current position.
    Is there any way to debug, what's going on underneath this API?
     
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,940
    Nope. Unity's navmesh is a very frustrating black box.

    That being said, you should at least be able to see what the navmesh looks like if you have the navmesh tab open, or select one of the nav components.
     
  5. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    40
    Thanks for replying, are you familiar with any "in-depth" sources that I can look for that might cover this topic?
     
  6. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,940
    Not really.

    If you open your navigation tab, how does the mesh look? Is your obstacles actually cut out?
     
  7. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    40
    I'm at work, so I can't test it right now, but I do remember that at least 1 bake had part of the terrain not coloured (at the navigation tab)
     
  8. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    40
    Here is an example of the issue that I'm facing.
     

    Attached Files:

  9. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    40
    I further debugged the path that is generated: it seems that before I assign ANY destination to the agent, it already has a prior set destination, even after I reset it, the agent's destination remains (to that far remote point that the next position seems to be AFTER I assign the destination), which by the way after assigning the desired path, the next position is indeed the above point.

    can any unity dev please help me with this? it does not make any sense.
     
  10. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    40
    I finally managed to solve the issue by doing the following:
    1. instantiate a bot
    2. set it's position according to state
    3. set it's NavAgent.nextPosition to the above position ---- that's the fix

    I'm not sure why this was required, hope it will help other people that get troubles with this system.
     
unityunity