Example Scenarios

Step by Step Guides

This section provides practical step-by-step examples for setting up the Runtime NavMesh Baker in different scenarios.

Tip: The package includes 2 example scenes that match these 2 scenarios.


Example 1: Static Scene with Runtime Baking

Use this setup when you have a large but mostly static scene (e.g., an open map with buildings/props) where you just want AI to navigate near the player, without baking a giant navmesh in advance.

Steps

  1. Add the Service

    • From the menu, go to GameObject → Runtime NavMesh Baker → Add NavMeshBakerService.

    • This automatically creates a NavMeshBakerService in your scene.

  2. Create a Profile

    • Right-click in the Project window → Create → Runtime NavMesh Baker → Bake Profile.

    • Assign this profile to the service.

    • Recommended starting settings:

      • Bake Mode = Continuous AABB

      • Base Bounds Size = (20, 20, 20)

      • Move Threshold = 3m

  3. Assign a Center Target

    • Drag your Player GameObject (or Main Camera) into the Center Target field.

  4. Add a Dynamic Surface

    • Select your level root or terrain object.

    • From the menu, choose GameObject → Runtime NavMesh Baker → Add DynamicNavMeshSurface.

    • Configure Collect Geometry (RenderMeshes or PhysicsColliders).

  5. Play & Test

    • Enter Play mode.

    • The navmesh will automatically bake around the player as they move.

    • AI agents can now spawn and pathfind in the baked region.


Example 2: Procedural / Streaming World

Use this setup when you have a procedural or streaming environment (e.g., procgen terrain, modular tiles, or streamed chunks).

Steps

  1. Add the Service

    • Use GameObject → Runtime NavMesh Baker → Add NavMeshBakerService to add the service.

  2. Create a Profile

    • Right-click in the Project window → Create → Runtime NavMesh Baker → Bake Profile.

    • Assign the profile to the service.

    • Recommended starting settings:

      • Bake Mode = Grid Cells

      • Cell Size XZ = (32, 32) (match your tile size)

      • Cell Height = 20

      • Rings = 1 (3×3 cells)

      • Cell Rebake Interval = 0.25s

      • Hysteresis = 0.15

  3. Assign a Center Target

    • Drag your Player GameObject (or Camera) into the Center Target field.

  4. Mark Surfaces as Dynamic

    • Add DynamicNavMeshSurface to any tile, chunk, or prefab that should participate in baking.

    • Surfaces automatically register/unregister with the service when spawned/destroyed.

  5. Spawn Procedural Content

    • Ensure new objects are on a layer included in the profile’s Layer Mask.

    • Place them under a DynamicNavMeshSurface so they’re collected at bake time.

  6. Play & Test

    • Enter Play mode.

    • As the player moves, navmesh cells stream in/out around them.

    • AI can immediately pathfind in newly spawned areas.


Example 3: One-Shot Full Scene Bake

Use this setup when you want to bake the entire scene once at runtime and never rebake again. This is ideal for large handcrafted maps where:

  • You don’t want to pre-bake in the editor (e.g., long bake times or editor crashes).

  • You only need one complete navmesh without streaming or continuous updates.

Steps

  1. Add the Service

    • From the menu: GameObject → Runtime NavMesh Baker → Add NavMeshBakerService

    • This creates a NavMeshBakerService in your scene.

  2. Create a Profile

    • Right-click in the Project window → Create → Runtime NavMesh Baker → Bake Profile

    • Assign this profile to the service.

    • Recommended starting settings:

      • Bake Mode = Continuous AABB

      • Base Bounds Size = Match the extents of your full map (e.g., (2000, 200, 2000))

      • Rebake Interval = 0 (disables rebaking)

      • Auto Start = On

  3. Mark Surfaces as Dynamic

    • Add DynamicNavMeshSurface to your terrain, level root, or any GameObject that should contribute geometry.

    • Configure Collect Geometry (RenderMeshes or PhysicsColliders).

  4. Trigger the Bake Once

    • In the inspector, select your NavMeshBakerService and press Bake Now.

    • At runtime, the service will build the entire navmesh in a single pass.

    • After completion, no further bakes are scheduled.

  5. Play & Test

    • Enter Play Mode.

    • Once the one-shot bake finishes, AI agents can spawn and navigate across the full map.

    • No ongoing baking will occur.


Notes

  • Startup Delay — For very large scenes, allow time for the one-shot bake to complete before spawning agents. Use the OnBakeCompleted event to synchronize spawns.

  • Memory Usage — A one-shot bake may produce a large navmesh data set; ensure your platform can handle the memory footprint.

  • No Streaming — This mode trades streaming efficiency for simplicity. Use Grid Cells mode (Example 2) if you need dynamic or infinite worlds.

  • Hybrid Approach — You can combine one-shot baking for a static base map with continuous baking for spawned/dynamic content.


Common Pitfalls & Tips

  • Use the Create Menu Always prefer GameObject → Runtime NavMesh Baker → … to add services and surfaces — this ensures default settings are sensible.

  • Don’t Forget Dynamic Surfaces If nothing bakes, check that your level or tiles have DynamicNavMeshSurface components.

  • Match Cell Size to Tiles In grid mode, set Cell Size XZ equal to your tile or chunk size. This keeps baking aligned with content.

  • AI Agents Need a NavMesh If you see warnings like Failed to create agent because there is no valid NavMesh, ensure a bake has finished before spawning agents. You can enqueue an initial bake via the service’s inspector.

  • Balance Concurrency Keep Max Concurrent Bakes low (1–2) to avoid CPU spikes.

  • Use Area Costs Wisely Set traversal costs in the profile to make AI prefer roads, avoid hazards, etc.


Next Steps

  • See the Service page for advanced API (manual bakes, events).

  • See the Profile page for detailed field explanations.

  • Check the Upgrading page if migrating from the legacy NavMeshBaker.

Last updated