NavMeshAgent SetDestination Error

使用 NavMeshAgentSetDestination函数,一直报错 "SetDestination" can only be called on an active agent that has been placed on a NavMesh. 导致寻路失败。

导航网格生成完好,Destination的点使用 NavMesh.SamplePosition 验证过,也定会在可行走区域内。

Debug许久未果,后在Unity Forum找到答案。

If you create a NavMeshAgent and set its position via transform.position=... and then try to SetDestination, it fails because the NavMeshAgent did not recognize the position change and does not know that it already is on the NavMesh. Use NavMeshAgent.Warp instead of transform.position to initialize the position before calling SetDestination.





王小兵 /
Published under (CC) BY-NC-SA in categories Unity3d  tagged with Unity3d