Unity NavMesh导航报错“SetDestination“ can only be called on an active agent that has been placed on a Na
在使用NavMeshAgent進行導航的時候,發現調用SetDestination一直報錯,報錯顯示是:
"SetDestination" can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.AI.NavMeshAgent:SetDestination(Vector3)
但是查看地圖,發現Bake過了,Agent也在地圖上啊,照理說會自動關聯到NavMesh地圖上的。
后來發現是因為NavMeshAgent不能直接設置position因為那樣他不知道他現在在哪里。
如果您創建一個 NavMeshAgent 并通過 transform.position=... 設置它的位置,然后嘗試 SetDestination,它會失敗,因為 NavMeshAgent 沒有識別位置變化并且不知道它已經在 NavMesh 上。在調用 SetDestination 之前,使用 NavMeshAgent.Warp 而不是 transform.position 來初始化位置。
錯誤代碼:
character.transform.position = pos;正確代碼:
character.Warp(pos);參考鏈接:
"SetDestination" can only be called on an active agent that has been placed on a NavMesh. - Unity AnswersUnity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.https://answers.unity.com/questions/507534/setdestination-can-only-be-called-on-an-active-age-1.html
總結
以上是生活随笔為你收集整理的Unity NavMesh导航报错“SetDestination“ can only be called on an active agent that has been placed on a Na的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux下mkdir和windows下
- 下一篇: linux下C语言mkdir,Linux