Hello,
I am implementing navmesh navigation in my project. My map already has walkable area baked:
I have a prefab with NavMesh Agent component and a script that sets it’s destination:
void Start(){
mBasePosition = GameObject.FindGameObjectWithTag ("Player").transform.position;
mNavMeshAgent = GetComponent<NavMeshAgent> ();
mNavMeshAgent.destination = mBasePosition;
}
When I put this prefab in a scene manually (drag into scene) and start the game , navigation works without problems. But when I instantiate it from a script at runtime (prefab spawner), I get a following error when trying to set destination:
“SetDestination” can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.AI.NavMeshAgent:set_destination(Vector3)
EnemyMovement:Start() (at Assets/Game/Scripts/Game/Enemy/EnemyMovement.cs:21)
Any ideas how to solve this ?
Regards, L