1
\$\begingroup\$

Anyone know what can cause NavMeshAgent.CalculatePath to return false and give a path with PathInvalid status?

  • I have two characters; each character has a NavMeshAgent. Character x is a standard Humanoid, character Y is a vehicle with a custom agent type.
  • Characters start out in scene A, which has two NavMeshes, one for each type, and both are able to navigate just fine.
  • Characters get moved to DontDestroyOnLoad so that scene A can be unloaded and scene B can be loaded.
  • Scene B has two NavMeshes, one for each type.
  • Characters are placed on the ground, on a valid NavMesh location.
  • NavMeshAgent is asked to path to another valid location on the NavMesh. Character Y (the weird one) paths just fine, but for character X, the call to CalculatePath fails and the NavMeshPath object's status is PathInvalid.

I honestly have no idea what's going on here. If anything, I'd expect pathing to work for X and fail for Y, due to it being a nonstandard (and larger) agent. Not sure if the scene change is relevant or not; including it just in case it is, and to show that the basic setup is working for 3/4 scenarios here. Anyone know how to go about debugging this?

\$\endgroup\$
  • \$\begingroup\$ "Not sure if the scene change is relevant or not" - can you reproduce the problem without the scene change? What's the value of X's isOnNavMesh property when you start to path? Have you tried working with the navMeshOwner to verify X is trying to path on the correct navmesh? \$\endgroup\$ – DMGregory Jul 28 at 21:49
  • \$\begingroup\$ @DMGregory isOnNavMesh is true, navMeshOwner is null. (Which seems like quite the odd combination!) When I hack it to start out with the character in Scene B, everything works correctly and navMeshOwner is the NavMeshSurface like you'd expect. \$\endgroup\$ – Mason Wheeler Jul 29 at 0:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.