# Technical Details

Unity’s **AI Navigation** package does support runtime navmesh baking internally, but it exposes only a very low-level API.\
There is no editor tooling, no service layer, and no practical workflow for most teams.

The **Runtime NavMesh Baker** wraps these APIs in a structured, service-based system with intuitive inspectors, menu items, events, and samples — so designers, programmers, and technical artists can all configure runtime baking without writing custom infrastructure.

***

### Core Features

#### Coordinator-First Workflow

* The **BakerCoordinator** component is the main entry point.
* Owns a **NavMeshBakeProfile** (asset with all settings) and a **Center Target** (e.g., player or camera).
* Automatically attaches and manages the underlying **NavMeshBakerService**.

#### Service-Based Architecture

* **NavMeshBakerService** manages:
  * Dirty queueing and async bake scheduling
  * Continuous AABB baking, Grid Cell streaming, or One Shot baking
  * Agent expansion, seam link building, and concurrency control
* Normally hidden from end users — accessed via the Coordinator.

#### Dynamic Surfaces

* **DynamicNavMeshSurface** wraps Unity’s `NavMeshSurface`.
* Registers automatically with the Coordinator (optional auto-register).
* Provides inspector buttons to mark itself dirty, register/unregister, and ping its surface.

#### Profiles

* **NavMeshBakeProfile** ScriptableObjects hold all bake parameters:
  * Bake mode (**Continuous AABB**, **Grid Cells**, **One Shot**)
  * Bounds sizes, cell dimensions, hysteresis, and rebake intervals
  * Agent types, default area, and area costs
  * Concurrency limits and seam-link options
* Multiple profiles can be created and swapped quickly.

#### Event Hooks

* **BakerEvents** exposes static events:
  * `OnBakeStarted`, `OnBakeCompleted`, `OnBakeFailed`
  * `OnCombinedBakeStarted`, `OnCombinedBakeCompleted`
  * `OnOneShotBakeStarted`, `OnOneShotBakeCompleted` *(new in 1.4.0)*
* Ideal for gameplay hooks (e.g., spawning AI when the navmesh is ready).

#### Spawner Integration *(new in 1.4.0)*

* **NavMesh Placement Policies** on `SpawnEntry`:
  * *Require* → spawn only once a valid NavMesh exists (deferred if needed)
  * *Prefer* → spawn immediately; agent enables once navmesh is available
  * *Ignore* → place regardless of navmesh state
* **Deferred Placement Queue** ensures Require-policy spawns retry until successful.
* **Spawn Hints** (`EnemySpawnHintPoint` components) let designers author preferred spawn anchors with per-hint rules.

#### Seamless AI Integration

* Works directly with Unity’s built-in `NavMeshAgent`, `NavMeshQuery`, and `NavMesh.SamplePosition`.
* Agents automatically re-path when new bakes complete.

#### Non-Destructive Workflow

* Combine **static editor-baked navmeshes** with runtime baking.
* Useful for hybrid projects: static base levels + procedural/dynamic zones.

***

### System Architecture (At a Glance)

```
[ Unity NavMesh System (AI Navigation package) ]
        ▲
        │ (low-level runtime APIs: NavMeshData, UpdateNavMeshDataAsync)
        │
[ NavMeshBakerService ]
    - Centralized runtime baking logic
    - Manages DynamicNavMeshSurfaces
    - Async scheduling, dirty queues, perf metrics
    - Dispatches BakerEvents (per-surface, combined, one-shot)
        ▲
        │
[ BakerCoordinator (MonoBehaviour) ]
    - Primary entry point for users
    - Owns NavMeshBakeProfile + Center Target
    - Auto-registers child DynamicNavMeshSurfaces
    - Provides friendly methods: StartBaking, BakeAllNow, RunOneShotBake
        ▲
        │
[ Inspector & Editor Tooling ]
    - Quick Setup menu, asset creators, Bake Monitor window
    - Dynamic Surface inspector (mark dirty, register/unregister)
    - Spawn Hints inspector (new in 1.4.0)
```

This layered design separates the runtime engine (**Service**) from the editor/user entry points (**Coordinator, inspectors, menus**), making it both production-ready and approachable.

***

### Dependencies

* Unity **2022.3 LTS** or newer
* **AI Navigation** (`com.unity.ai.navigation`) – required core package
* Optional / samples only:
  * **TextMesh Pro** – used in sample UIs
  * **Cinemachine** – used in sample scenes for player camera control
