NavMeshAgent in unity not working

Marcus Mardis picture Marcus Mardis · Feb 4, 2016 · Viewed 11.9k times · Source

I am making a game in unity and it is throwing the error "Failed to create agent because there is no valid NavMesh" and i don't know what the problem is.

Setup Pic

using UnityEngine;
using System.Collections;

public class EnemyMotion : MonoBehaviour {
    public NavMeshAgent agent;
    public Rigidbody rb;
    public GameObject otwt;

    void Start () {
        rb = GetComponent<Rigidbody>();
        agent = GetComponent<NavMeshAgent>();
    }
    void Update () {
        gameObject.transform.Rotate(270, 0, 0);
        agent.SetDestination(otwt.transform.position);
    }
}

Answer

JoRouss picture JoRouss · Mar 18, 2016
  • Go to Window -> Navigation.
  • Click on the Bake tab.
  • Click on Bake in the bottom right corner.

This will bake the NavMesh and your NavMeshAgent will now work. Right now you have no NavMesh, so your Agents don't know where they can move/walk.