Quick answer: Edit-time baked NavMesh ignores runtime-spawned geometry. Use the NavMeshComponents package’s NavMeshSurface with BuildNavMesh() at runtime, or apply NavMeshObstacle with carving for dynamic blockers.

Here is how to fix Unity NavMeshAgent paths that ignore objects spawned at runtime, treating new walls as walkable. The classic baked NavMesh is a snapshot of edit-time geometry; runtime spawns need explicit treatment.

The Symptom

Spawn a wall prefab via Instantiate. NavMeshAgent walks straight through it. Pre-existing walls block correctly.

What Causes This

Bake is static. Window → AI → Navigation Bake records geometry at bake time only.

NavMeshObstacle missing. Without a runtime carve component, dynamic objects do not affect path queries.

NavMeshSurface not used. The NavMeshComponents package’s NavMeshSurface allows runtime rebuilds.

The Fix

Step 1: Install NavMeshComponents. Window → Package Manager → AI Navigation. Provides NavMeshSurface, NavMeshObstacle (richer), NavMeshModifier.

Step 2: Use NavMeshSurface for runtime bakes.

using Unity.AI.Navigation;
using UnityEngine;

public class NavBaker : MonoBehaviour
{
    [SerializeField] private NavMeshSurface surface;

    public void SpawnAndRebake(GameObject prefab, Vector3 pos)
    {
        Instantiate(prefab, pos, Quaternion.identity);
        surface.BuildNavMesh();   // async; agent paths refresh
    }
}

BuildNavMesh on each surface is the simplest. For large worlds, partition into multiple surfaces to keep rebuild cost low.

Step 3: Use NavMeshObstacle for cheap dynamic blockers.

// On the dynamic prefab
// Add NavMeshObstacle, enable Carve and Move Threshold ~0.1

Carving runtime-modifies the existing mesh without a rebuild. Cheaper than rebake but only adds holes — no new walkable surfaces.

Step 4: For agents on new geometry, rebake. Carving handles blockers; new walkable terrain requires a NavMeshSurface BuildNavMesh.

Step 5: Use UpdateNavMesh for incremental updates.

var data = surface.navMeshData;
NavMeshSurface.UpdateNavMesh(data, surface.GetBuildSettings(), sources, surface.GetVolume());

Faster than full rebuild for small additive changes.

“NavMeshSurface for runtime bake. NavMeshObstacle for cheap blockers. Pick by whether you need new walkable surfaces.”

Related Issues

For NavMesh edge issues, see Agent Stuck on Edge. For agent path updates, see Path Not Updating.

NavMeshSurface for runtime walkables. NavMeshObstacle for blockers. Bake covers spawns.