Hello everyone,
I was following the Unity documentation for creating a NavMeshAgent using the steps outlined here: Creating a NavMesh Agent | AI Navigation | 1.1.5
After setting up the Cylinder (as my agent) and Sphere (as the destination), and baking the NavMesh, I pressed “Play” to run the scene. However, I encountered the following error:
“SetDestination can only be called on an active agent that has been placed on a NavMesh”
My code
using UnityEngine;
using UnityEngine.AI;
public class MoveTo : MonoBehaviour {
public Transform goal;
void Start () {
NavMeshAgent agent = GetComponent<NavMeshAgent>();
agent.destination = goal.position;
}
}
#Steps I followed: (After baked NavMesh for my 3d model)
- Created a Cylinder (for the agent) and added the NavMeshAgent component to it.
- Created a Sphere as the goal.
- Moved the Cylinder and Sphere to areas on the baked NavMesh.
- Assigned the Sphere to the “Goal” property of the agent.
- Pressed Play and encountered the error.
Has anyone encountered this issue or can help me figure out why my agent isn’t “placed on” the NavMesh?
Any suggestions or solutions would be appreciated!
Thanks!