2

In most cases, when I call SetDestination() on a NavMeshAgent to go to a location that no complete path exists, the agent will go as close to the location as possible and then stop.

When I try to run SetDestination() continuously in an agent's Update() to an unreachable location, occasionally the agent just does not move at all. After calling a separate SetDestination() (to the same location) from a different script that sets a destination on mouseclick, the agent moves as close to the location, which did not occur when SetDestination() was called in Update().

Why is this happening and when does unpredictable behavior occur with NavMeshAgents and SetDestination()?

c0der
  • 18,467
  • 6
  • 33
  • 65
Roger Wang
  • 565
  • 2
  • 12
  • 30
  • if it cant get here it doesnt make a path - check it has a path – BugFinder May 27 '20 at 00:10
  • The agent typically goes as close to the destination as possible if it cannot reach its exact location. – Roger Wang May 27 '20 at 00:12
  • 1
    calling set destination every frame is a bit excessive, it can still be working out a path from the last one – BugFinder May 27 '20 at 00:49
  • Wow, when I called SetDestination() once every 2 seconds instead, the agent always moved to the blocked-off location, although once every few playthroughs, the agent would halt temporarily when calculating a new path. The reason why I originally called SetDestination() every frame was because the obstacles in my game could change positions and I wanted the agents to use the shortest path every frame. – Roger Wang May 27 '20 at 01:02
  • If the obstacles are marked properly the path should auto update – BugFinder May 27 '20 at 21:00
  • I had the same issue, and i noticed if SetDestination in the same frame as BuildNavMeshAsync, it won't work – Данияр Jul 04 '23 at 15:10

0 Answers0