NavMeshBakerService

Internal Runtime Manager for Dynamic Navmesh Baking

The NavMeshBakerService is the internal runtime manager for procedural and dynamic baking. It is owned by the BakerCoordinator and there should only be one instance at runtime.

The Baker Coordinator will add one automatically if it does not exist. Optionally add to the same GameObject as the Baker Coordinator (or click the 'Add Service Component' button on the Baker Coordinator)

Overview

  • Central scheduler for async baking jobs

  • Manages all DynamicNavMeshSurface components

  • Coalesces dirty regions, throttles concurrency, avoids redundant work

  • Profile-driven via NavMeshBakeProfile

  • Follows a Center Target to keep navigation data relevant (when required)


Bake Modes

  • Continuous AABB Maintains a moving bounding box centered on the target. Re-bakes as the target moves beyond thresholds.

  • Grid Cells Divides the world into cells and keeps a configurable ring of cells baked around the target.

  • One Shot (new in 1.4.0) Performs a single bake of the entire map volume at startup or on-demand.

    • No continuous rebakes.

    • Ideal for handcrafted maps or cases where pre-baking in editor isn’t feasible.

    • Works with all registered DynamicNavMeshSurface components at the time of bake.


Event Hooks

OnBakeStarted(DynamicNavMeshSurface surface, Bounds region);
OnBakeCompleted(DynamicNavMeshSurface surface, Bounds region, float durationSeconds);
OnBakeFailed(DynamicNavMeshSurface surface, Bounds region, string reason);

Notes

  • In One Shot mode, these events fire once per surface/agent when the single bake runs.

  • You can subscribe to OnBakeCompleted to safely spawn agents once a navmesh exists.


Inspector (Service)

Although usually hidden behind the Coordinator, the service inspector exposes:

  • Bake Profile

  • Center Target

  • Enable Logs

  • Draw Gizmos

Buttons

  • Set Center = Main Camera

  • Create Profile

  • Open Profile

  • Enqueue (mode-aware)

    • Continuous AABB: enqueue a bounding-box bake around the target

    • Grid Cells: enqueue the active cell and ring

    • One Shot: enqueue a single full-scene bake

  • Enqueue Bake All Surfaces

  • Clear All NavMeshes (Editor-only)

Runtime Status

  • Registered Surfaces

  • Dirty Queue size

  • In-Flight Jobs

  • Skipped(no-src)

  • p95 timings for Update / Collect / Schedule (via GetPerfSnapshot)


Public API (Service)

void SetCenterTarget(Transform t);

void RegisterSurface(DynamicNavMeshSurface s);
void UnregisterSurface(DynamicNavMeshSurface s);

void MarkDirty(DynamicNavMeshSurface s, Bounds? region, int agentTypeId, int priority);

void EnqueueBakeAroundTarget();     // Continuous AABB
void EnqueueCurrentGridCells();     // Grid Cells
void EnqueueBakeAllSurfaces();      // All modes
void EnqueueOneShotBake();          // new in 1.4.0

Best Practices

  • Mode choice

    • Continuous AABB → compact/roaming maps

    • Grid Cells → large/procedural maps

    • One Shot → full handcrafted maps baked once at runtime

  • Concurrency Keep max concurrent jobs low (1–2) to avoid CPU spikes.

  • Spawner integration Use OnBakeCompleted to defer agent spawning until navmesh data exists. Combine with SpawnEntry placement policies (Require, Prefer, Ignore) for robust AI placement.

  • Debugging Enable gizmos to visualize volumes, bake queues, and surface contributions.

Last updated