Performance: NavMesh baking
NavMesh baking affects the initial loading time and runtime pathfinding performance by precomputing walkable areas.
Bake NavMesh once in editor or at scene load, then reuse baked data at runtime
NavMeshSurface.BuildNavMesh() called every frame or frequently at runtime| Pattern | CPU Usage | Runtime Impact | Memory Usage | Verdict |
|---|---|---|---|---|
| Runtime frequent baking | High CPU spikes | Frame drops and stutters | Moderate | [X] Bad |
| Prebaked NavMesh | One-time CPU cost | Smooth runtime pathfinding | Higher memory for NavMesh data | [OK] Good |
using UnityEngine;
using UnityEngine.AI;
public class BakeNavMesh : MonoBehaviour {
public NavMeshSurface surface;
void Start() {
surface.BuildNavMesh();
Debug.Log("NavMesh baked");
}
}
What will be the output when this script runs?public NavMeshSurface surface;
void Start() {
surface.BakeNavMesh();
}
What is the error and how to fix it?Pass the test and this pattern moves unknown