Prefabs and NavMesh

I am trying to make a small RTS game to sort of make an idea. I am trying to control a “Player” and this works when it isn’t a prefab. Once i add in 1 prefab or mutiple is doens’t work anymore and it gives a error with the NavMesh.

This is the error: “SetDestination” can only be called on an active agent that has been placed on a NavMesh.
APLayerController:Update() (at Assets/APLayerController.cs:35)

This is my scripts:
using UnityEngine;
using UnityEngine.AI;

public class APLayerController : MonoBehaviour {

public Camera _cam;
public Transform player;
public NavMeshAgent _playerMesh;

private float selectDistance = 100f;
public bool playerControl = false;

// Use this for initialization
void Start () {

// Update is called once per frame
void Update () {
    RaycastHit hit;

    if (Input.GetMouseButtonDown(0) && playerControl == false) {
        Ray ray = _cam.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out hit) && playerControl == false) {
            if ( == "Player" && playerControl == false) {
                playerControl = true;
    if ((Input.GetMouseButtonDown(0)) && (playerControl)) {
        Ray ray = _cam.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out hit) && (playerControl)) {
            if ( == "Ground" && (playerControl)) {
                _playerMesh.destination = hit.point;

    if (Input.GetButton("Fire3") && playerControl) {
        playerControl = false;



The Code doesn’t really matter for this problem. The NavMesh Is usually created for a completed scene on static objects, but if the envrionments become prefabs this process can run into problems.

Try using the NavMeshComponents to create a dedicated NavMesh to your prefab.