title: SetDestination and active agent/NavMesh issue with Unity Game
body: <p>I am working in unity 5 on a game and I am currently getting this error:</p>
  
  <p>"SetDestination" can only be called on an active agent that has been placed on a NavMesh.
  UnityEngine.NavMeshAgent:SetDestination(Vector3)
  EnemyMovement:Update() (at Assets/Scripts/Enemy/EnemyMovement.cs:25)</p>
  
  <p>My code for the enemyMovement script is: </p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  
  public class EnemyMovement : MonoBehaviour
  {
  Transform player;
  PlayerHealth playerHealth;
  EnemyHealth enemyHealth;
  NavMeshAgent nav;
  
  
  void Awake ()
  {
      player = GameObject.FindGameObjectWithTag ("Player").transform;
      playerHealth = player.GetComponent &lt;PlayerHealth&gt; ();
      enemyHealth = GetComponent &lt;EnemyHealth&gt; ();
      nav = GetComponent &lt;NavMeshAgent&gt; ();
  }
  
  
  void Update ()
  {
      if(enemyHealth.currentHealth &gt; 0 &amp;&amp; playerHealth.currentHealth &gt; 0)
      {
          nav.SetDestination (player.position);
      }
      else
      {
          nav.enabled = false;
      }
   }
  }
  </code></pre>
  
  <p>Now I know that there is almost an identical question here: <a href="https://stackoverflow.com/questions/30497067/unity-setdestination-can-only-be-called-on-an-active-agent-that-has-been-pla">Unity - &quot;SetDestination&quot; can only be called on an active agent that has been placed on a NavMesh. UnityEngine.NavMeshAgent:SetDestination(Vector3)</a> However, the question does not seem to have a firm response and I have tried doing some of the responses and nothing appears to work. I will say that my game does work fine. However, I have added an ability that if the player presses 'B' then all of the enemies will die on the screen. When I press 'B' the enemies die but the system 'crashes' and I get that error message. </p>
  
  <p>EnemyManager.cs: </p>
  
  <pre><code>        public void Kill(int InstanceID)
      {
          if (EnemyManager.Instance.EnemyList.ContainsKey(InstanceID))
              EnemyManager.Instance.EnemyList.Remove(InstanceID);
      }
  
      public void DeathToAll()
      {
          Dictionary&lt;int, Object&gt; TempEnemyList = new Dictionary&lt;int, Object&gt;(EnemyManager.Instance.EnemyList);
          foreach (KeyValuePair&lt;int, Object&gt; kvp in TempEnemyList)
          {
              // kvp.Key;   // = InstanceID
              // kvp.Value; // = GameObject
  
              GameObject go = (GameObject)kvp.Value;
              go.GetComponent&lt;EnemyHealth&gt;().Death();
          }
  
      }
  </code></pre>
  
  <p>Enemyhealth.cs</p>
  
  <pre><code>        public void Death ()
      {
          // The enemy is dead.
          isDead = true;
  
          // Turn the collider into a trigger so shots can pass through it.
          capsuleCollider.isTrigger = true;
  
          // Tell the animator that the enemy is dead.
          anim.SetTrigger ("Dead");
  
          // Change the audio clip of the audio source to the death clip and play it (this will stop the hurt clip playing).
          enemyAudio.clip = deathClip;
          enemyAudio.Play ();
  
          // Kill the Enemy (remove from EnemyList)
          // Get the game object associated with "this" EneymHealth script
          // Then get the InstanceID of that game object.
          // That is the game object that needs to be killed.
          EnemyManager.Instance.Kill(this.gameObject.GetInstanceID());
  
  
      }
  </code></pre>