Zombie AI not working

i am making a zombie shooter but when i try to make it so that the zombie wonders around when it can’t see the player i keep getting this error: “SetDestination” can only be called on an active agent that has been placed on a NavMesh. UnityEngine.AI.NavMeshAgent:SetDestination(Vector3) EnemyController:Wander() (at Assets/scripts/Enemy/EnemyController.cs:69) EnemyController:Update() (at Assets/scripts/Enemy/EnemyController.cs:33)

using UnityEngine;

public class ShootingFPS : MonoBehaviour
{
    public Rigidbody bullet;//the bullet it self
    public Transform spawner;//the point that the bullet spawns
    public float bulletSpeed = 7000.0f;//the speed of the bullet

    public static int mag = 30;
    public static int ammo = 100;
    float reloadTime = 1.5f;//the amount of time it takes to reload
    public static bool reloading = false;

    void Update ()
    {
        if (Input.GetMouseButtonDown(0) && mag > 0 && !reloading)
        {
            mag = mag - 1;//removes a bullet
            Rigidbody bulletInstance = Instantiate(bullet, spawner.position, spawner.rotation) as Rigidbody;//spawns the bullet
            bulletInstance.AddForce(spawner.forward * bulletSpeed);//added the force to the bullet
        }

        if (Input.GetKeyDown("r"))
        {
            if (!reloading)
            {
                this.GetComponent<Animator>().Play("reloadAnimatoin", -1, 0.0f);
                reloading = true;
            }
        }

        if (reloading)
        {
            if (reloadTime > 0)
            {
                reloadTime -= Time.deltaTime;
            }
            else if(ammo > 0)
            {
                mag -= 30;
                ammo += mag;
                mag = 30;
                reloadTime = 1.5f;
                reloading = false;
            }
          
        }
    }

}

Please put all your code in code tags in the forums. You can edit your post on the bottom of it.

Have you baked your navmesh? https://docs.unity3d.com/Manual/nav-BuildingNavMesh.html

1 Like

error: “SetDestination” can only be called on an active agent that has been placed on a NavMesh

well, how about trouble shooting?
is the nav agent active?
is it on the nav mesh?

also, as @ said, use code tag because no one is gonna read an unformatted script

edit: you posted the wrong script i think

Thanks

I usually run across this when I place an AI just off of the mesh. I snap my AIs to the nearest point of the navmesh on Start