我在编辑器中收到此错误
"SetDestination" can only be called on an active agent that has been placed on a NavMesh.
这些是我在解决问题时尝试的步骤:
- 将 NavmeshAgent 扭曲到 NavMesh 位置
- 手动将 NavMeshAgent 移动到 NavMesh
- 重新烘焙 NavMesh 并执行上述步骤
- Creating a box with NavMeshAgent and a new NavMesh
扭曲导航网格体代理位置有时会导致错误,特别是当它从一个导航网格体转到另一个导航网格体时。
这是一个奇怪的错误,但似乎检测代理是否不在导航网格上,然后禁用并重新启用代理 - 将解决问题(在我的情况下确实如此)。
我在我的项目中通过在扭曲时执行以下操作解决了这个问题。
//use some existing reference to your NavMeshAgent
NavMeshAgent agent = PlayerController.instance.GetComponent<NavMeshAgent>();
//This will fire when you get the error you're describing.
if (!agent.isOnNavMesh)
{
Vector3 warpPosition; //Set to position you want to warp to
agent.transform.position = warpPosition;
agent.enabled = false;
agent.enabled = true;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)