Unity NavMesh导航报错“SetDestination“ can only be called on an active agent that has been placed on a Na

编程入门 行业动态 更新时间:2024-10-25 23:32:08

在使用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/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

本文发布于:2023-06-13 08:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1363786.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报错   SetDestination   Unity   NavMesh   agent

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!