... Can only be called on an Active Agent that has been placed on a Nav Mesh?

I have no errors before I start the game but these things usually pop up a minute into run time. I know these are coming from the scrips of an Ai unit i made with a Nav Mesh Agent component. the map is fully baked as well. However I have at least 50 of these units and I only get around 3-5 of these errors.

Here is the error message…

““SetDestination” can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.NavMeshAgent:set_destination(Vector3)”

and here is the code where this error points to…

function inCombatAi()
{
	if(DEBUG)Debug.Log(inCombat);
	
	if(inCombat == false && targetObj == null && fireOnce == true)
	{	
		if(DEBUG)Debug.Log("Finding Destination");
		Nav.destination = FindClosestTarget().transform.position;
	}
	
	if(inCombat == true && targetMemory !== null && targetDes !== null && gameObject !== null && Nav !== null)
	{
		if(DEBUG)Debug.Log("Finding Target");
		var target = targetDes.transform;	
		Nav.destination = target.position;		
		
		var angleCheck = Vector3.Angle(transform.forward, target.position - transform.position) < 15;
		var distCheck = Nav.remainingDistance < range;
		var distCheckTwo = Nav.remainingDistance >= range;tin
		
		
		if(angleCheck && distCheck)
		{
			Nav.stoppingDistance = range * 0.8;
			Nav.ResetPath();
		}
		if(!angleCheck && distCheckTwo)
		{
			Nav.stoppingDistance = range * 0.1;
			Nav.ResetPath();
		}
	}
}

I read around the forums (REALLY awesome community btw) and someone said that its because the object isnt on the Nav mesh and a fix would be just aligning the object right on top of the Mesh… however these errors pop up during run time and I believe something happens that causes the unit to maybe jump up. I dont really know. If someone can help point out a way ti fix this, I would really appreciate it!

Thanks in advance!!

Old thread, I know–but just went through the same thing. There’s an unintuitive sequence of events that cause this.

1. Destoy(something)
2. something.Update event
3. something.OnDestroy event

Fortunately OnDisable seems to fire regularly between Destroy and Update.

So far, this is working –

public class Something {
  public NavMeshAgent agent;
  public bool doUpdate;
  public Vector3 dest;
  void Start () {
    agent = GetComponent<NavMeshAgent>();
    doUpdate = true;
    dest = Vector3.zero;
  }
  void Update () {    
    if (doUpdate)
    {
      // find dest
      agent.SetDestination(dest);
    }
  }
  void OnDisable()
  {
      doUpdate = false;
  }
}

Don’t forget scene floor always must be static for NavMeshAgent