Enemy AI keeps walking through walls

I’ve followed a Unity video available on YouTube to create a state machine for your AI, but however, when the enemy is patrolling, they walk through walls. I’ve tried to add the RigidBody component onto the enemy, but this completely bugs out their movement going to each waypoint.

Here is the code that makes the AI move to each waypoint

private void Look()
{
    RaycastHit hit;
    if (Physics.Raycast(enemy.eyes.transform.position, enemy.eyes.transform.forward, out hit, enemy.sightRange) && hit.collider.CompareTag("Player"))
    {
        enemy.chaseTarget = hit.transform;
        InChaseState();
    }

}

void Patrol()
{
    enemy.meshRendererFlag.material.color = Color.green; //Test to see what state the enemy is in
    enemy.navMeshAgent.destination = enemy.waypoints[nextWaypoint].position; //Select the current waypoint
    enemy.navMeshAgent.Resume(); //Start walking again

    if (enemy.navMeshAgent.remainingDistance <= enemy.navMeshAgent.stoppingDistance && !enemy.navMeshAgent.pathPending) //Checking to see if we've reached our destination
    {
        nextWaypoint = (nextWaypoint + 1) % enemy.waypoints.Length; //Go to next waypoint and should loop as expected
    }
}

Anyone know how to edit this code to make the enemy walk around walls in the map to reach each waypoint? Thanks.

It looks like its using the Navmesh for movement- so the walls are probably not marked as “static” and haven’t been added to the navmesh- switch to the Navigation tab and check if the walls carve out the navmesh preventing the agent from walking there or not-

If they don’t carve out the navmesh- check the “Static” box on the walls and re-bake the navmesh