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

Mis-feature in NavmeshAgent regarding Off-mesh Links

Discussion in 'Navigation' started by Sluggy, May 5, 2019.

  1. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    I finished tracking down a long term bug that was the result of what I would deem a misfeature. Once I read the documentation I realized what was going on but I still feel this behavior is incorrect.

    When NavMeshAgent.Resetpath() is called, if the agent is currently on an off-mesh link, they immediately complete the link by teleporting to the end point of said link. This happens even if Auto-Traversal of off-mesh links is set to false. I feel this is incorrect behavior as there are many cases where one would always want a custom traversal motion and still be able to call ResetPath(). As it stands right now, ResetPath() is out of the question for me and I cannot rely on it ever.

    At the very least, this is quite confusing and likely to lead to developers wasting a lot of time unless they perform a very close read of the documentation.
     
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Interesting find. I'd try and directly reach the devs, I doubt they'll happen to stumble on your forum post here unfortunately.
     
    Sluggy likes this.
  3. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Hmm good point. Granted, I posted here because the Feedback site has been depreciated (maybe even shutdown by now) and I was under the impression this was the place to post such issues now.

    I'm not too familiar with the particular sub-forum or who to tag for NavMesh related issues, any suggestions?
     
  4. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Yeah, that's going to be a bit of a problem, I can't remember the last time I saw a Unity Staffer in this sub and have no clue who might be in charge of navigation right now, or what their forum handles are.
    I think the best bet would be to tag a moderator and hope they know more.
    With that, I summon thee, @hippocoder !
     
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Unfortunately there's nothing I can add, and I feel navigation is probably understaffed from what I can imagine. Certainly it's very capable but has a ton of these little quirks. Are you using the github version?

    A quick fix in your case if you want to continue using the agent is to just call stop or set destination where it is before telling it the path is complete. When an agent has control, telling it to complete isn't "stop calculating movement" but "complete it!", so try some func calls like ResetPath and so on. Have a filddle till it stops being daft and don't assume it means what you think it means (the thinking behind navmesh is a little different to the rest of Unity's API and that's becoming the norm these days I guess).

    --

    In my case I never actually use the agent itself for movement but disable position and rotation updates inside init with:
    Code (CSharp):
    1. agent.updatePosition = false;
    2. agent.updateRotation = false;
    Then I update it myself each frame (not sure how much I need to do here):
    Code (CSharp):
    1. agent.speed = actor.properties.speed;
    2. agent.velocity = actor.controller.rb.velocity;
    3. agent.nextPosition = actor.transform.position;
    And finally grab the intended velocity when needed from:
    Code (CSharp):
    1. agent.desiredVelocity
    To apply movement myself, be it a direction vector (with some extra code) or just used as-is with agent settings. This will cause character to also collide with environment but should your character be knocked off course and have auto repath enabled, the above code will calculate a new path, so you can properly control a creature or whatever physically or otherwise.

    A quick fix in your case if you want to continue using the agent is to just call stop or set destination where it is before telling it the path is complete.

    Not sure why I'm doing AI support but if it helps, it helps! This section of the forum is often unloved.

    Edit: added a couple of old methods from my code - untested for the longest time as I've not been working on AI for a while but you may find a glimmer of interest....

    Code (CSharp):
    1.         public void StopMoving()
    2.         {
    3.             if (agent.isOnNavMesh)
    4.             {
    5.                 agent.CompleteOffMeshLink();
    6.                 agent.ResetPath();
    7.             }
    8.         }
    9.  
    10.         public bool Arrived()
    11.         {
    12.             return !agent.pathPending && agent.remainingDistance < agent.stoppingDistance;
    13.         }
     
  6. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Yeah sorry, you're just the mod I've seen the most around and your name stuck in my mind ;)
     
  7. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    I am using the built-in navmesh generator for now but this behavior is the same regardless. Thanks for the ideas! I'll give the 'isStopped' idea a try but I suspect the behavior will be the same. I'll also try setting the destination to the current position to effectively cancel all motion and see if that helps. Once I've tested these I'll post back here to let others know the results.

    I don't mean to rag on the Unity Team since it's obvious there is a lot going on for them right now but I can't help but feel the NavMesh system (like many others) was released in a mostly functional state but with many refinements and quality-of-life features missing or badly implemented. I suppose it's possible that with the Data-Oriented stack looming on the horizon they are reconsidering core aspects of all of their systems and it would make sense that they wouldn't want to invest more time in a design that will eventually be phased out. Then again, they've had a habit seemingly abandoning some of these things for a very long time now ;)
     
  8. MallNinjaMax

    MallNinjaMax

    Joined:
    Apr 17, 2017
    Posts:
    25
    Gonna necro this thread, as I ran into the same problem. I think I found a solution. Warp() the agent to it's current position, just before calling the path reset. None of the other suggestions worked for me, but this one seems to.
     
    Last edited: Sep 2, 2020
    ejsingson and Sluggy like this.