0
0
Unityframework~10 mins

NavMesh baking in Unity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - NavMesh baking
Scene Setup with Geometry
Mark Walkable Surfaces
Open Navigation Window
Configure Bake Settings
Click Bake Button
NavMesh Data Generated
NavMesh Ready for Agent Pathfinding
NavMesh baking creates a navigation mesh from scene geometry so agents can find paths on walkable surfaces.
Execution Sample
Unity
using UnityEngine;
using UnityEngine.AI;

public class BakeNavMesh : MonoBehaviour {
    void Start() {
        NavMeshSurface surface = GetComponent<NavMeshSurface>();
        surface.BuildNavMesh();
    }
}
This script triggers NavMesh baking at runtime on the attached NavMeshSurface component.
Execution Table
StepActionInput/StateOutput/Result
1Scene loadedScene with floors and obstaclesGeometry ready for NavMesh
2Mark surfacesFloors marked as walkableWalkable areas identified
3Open Navigation windowUser opens NavMesh settingsSettings panel visible
4Configure bake settingsAgent radius, height, slope setBake parameters set
5Click BakeUser clicks bake buttonNavMesh baking starts
6Bake processGeometry and settings inputNavMesh polygons generated
7Bake completeNavMesh data createdNavMesh ready for pathfinding
8Use NavMeshAgent requests pathAgent navigates on NavMesh
9ExitNavMesh baked and usableProcess ends
💡 NavMesh baking ends after generating navigation data for agent pathfinding.
Variable Tracker
VariableStartAfter Step 2After Step 5After Step 7Final
Scene GeometryLoadedLoadedLoadedLoadedLoaded
Walkable SurfacesNoneMarkedMarkedMarkedMarked
Bake SettingsDefaultDefaultConfiguredConfiguredConfigured
NavMesh DataNoneNoneNoneGeneratedGenerated
Key Moments - 3 Insights
Why do we need to mark surfaces as walkable before baking?
Marking walkable surfaces tells the NavMesh baker which areas agents can walk on, as shown in step 2 of the execution table.
What happens if bake settings like agent radius are incorrect?
Incorrect settings cause the NavMesh to not fit the agent properly, leading to navigation errors, as configured in step 4 and affecting step 6.
Can NavMesh baking be done at runtime?
Yes, as shown in the code sample, calling BuildNavMesh() on a NavMeshSurface bakes the NavMesh during runtime.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step is the NavMesh data generated?
AStep 5
BStep 7
CStep 6
DStep 8
💡 Hint
Check the 'Output/Result' column for when NavMesh polygons are created.
According to the variable tracker, when does the NavMesh Data change from None to Generated?
AAfter Step 7
BAfter Step 5
CAfter Step 2
DAt Start
💡 Hint
Look at the 'NavMesh Data' row and see when it changes.
If the walkable surfaces are not marked, what will happen during baking?
ANavMesh will bake normally with all surfaces walkable
BBake settings will override walkable surfaces
CNavMesh will not generate any walkable areas
DBake will fail with an error
💡 Hint
Refer to step 2 and 6 in the execution table about walkable surfaces.
Concept Snapshot
NavMesh baking creates a navigation mesh from scene geometry.
Mark walkable surfaces before baking.
Configure agent settings (radius, height, slope).
Click Bake to generate NavMesh data.
Agents use NavMesh for pathfinding.
Full Transcript
NavMesh baking in Unity involves preparing your scene by marking which surfaces agents can walk on. You open the Navigation window, set bake parameters like agent size, and then click the Bake button. The system processes the geometry and settings to create a navigation mesh. This mesh allows agents to find paths and move around obstacles. You can also bake NavMesh at runtime by calling BuildNavMesh() on a NavMeshSurface component. Key steps include marking walkable surfaces, configuring settings, and baking to generate usable navigation data.