> For the complete documentation index, see [llms.txt](https://megacrush.gitbook.io/megacrush-unity-assets/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://megacrush.gitbook.io/megacrush-unity-assets/runtime-navmesh-baker/runtime-navmesh-baker-user-manual/frequently-asked-questions.md).

# Frequently Asked Questions

## FAQ & Examples

This section covers common questions and provides example scripts included with the package.

***

### How do I test that runtime baking is working?

Use the included **ClickToMoveController** sample.

**Namespace**: `MegaCrush.NavmeshBaker.Sample`

1. Attach it to a GameObject with a **NavMeshAgent**.
2. At runtime, left-click in the scene to move the agent.
3. The script:
   * Subscribes to `BakerEvents.OnBakeCompleted`.
   * Waits for the first bake.
   * Warps the agent safely onto the navmesh.
   * Enables input so you can click to move.

This demonstrates the pattern:

> **Wait for bake → enable agent → call `agent.SetDestination()`.**

***

### How can I spawn agents only after a navmesh is ready?

Use the included **SpawnOnBake** sample.

**Behavior**:

* Subscribes to `BakerEvents.OnBakeCompleted`.
* When the event fires:
  * Chooses a spawn position.
  * Calls `NavMesh.SamplePosition()` to snap to valid ground.
  * Instantiates the prefab.
* If “Only Once” is enabled, it spawns only on the first bake.

**Why it’s useful**:\
Prevents errors like:

> *“Failed to create agent because there is no valid NavMesh”*

when spawning AI too early.

***

### How can I see what’s being baked in Grid mode?

Use the included **Procgen Map** sample.

**Behavior**:

* Draws gizmos for the current grid cell and surrounding rings.
* Shows which regions will be enqueued around the player.

**Why it’s useful**:

* Helps tune `cellSizeXZ`, `rings`, and `hysteresis` in your **NavMeshBakeProfile**.
* Makes it easy to align baking cells with procedural tiles or streamed chunks.

***

### Unity throws errors about “Source mesh XXX does not allow read access.”

This is a Unity engine limitation. At runtime:

* If you bake from **Render Meshes**, Unity requires mesh assets to be marked **Read/Write Enabled**.
* If you bake from **Mesh Colliders**, the same rule applies.

By default, the Runtime NavMesh Baker enforces **Physics Colliders** mode to avoid this.

#### To fix:

1. Prefer **Physics Colliders** (default).
2. If you must use **Render Meshes** or **Mesh Colliders**:
   * Select the mesh in your Project.
   * In the **Model Importer**, enable **Read/Write**.
   * Click **Apply**.

Unity docs: [Mesh.isReadable](https://docs.unity3d.com/ScriptReference/Mesh-isReadable.html)

***

### Key Tips

* Always **subscribe to `BakerEvents.OnBakeCompleted`** before enabling or spawning agents.
* Use **GridBakeVisualizer** to validate cell setup before deployment.
* For runtime spawning systems, pattern logic after **SpawnOnBake**.
* If you see *Combined Mesh (root: scene)* errors, disable **Static Batching** for geometry that contributes to runtime baking.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://megacrush.gitbook.io/megacrush-unity-assets/runtime-navmesh-baker/runtime-navmesh-baker-user-manual/frequently-asked-questions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
