02 — Setup and NavMesh

What to install

What a NavMesh is

A NavMesh is a pre-computed map of where characters can walk — a mesh laid over your floors, with holes where walls and obstacles are, plus data about slopes and drops. Agents then ask "route from A to B" and get back a path that automatically hugs corners and avoids obstacles. You never write pathfinding code; you bake the map and steer with two lines:

using UnityEngine.AI;                 // core module, always available
agent.SetDestination(player.position);  // that's the whole chase

The three pieces (mirror of the UI Toolkit trio)

  1. NavMeshSurface (component, from the AI Navigation package) — put it on your level root; its Bake button scans the geometry and builds the mesh. Toggle the scene-view NavMesh overlay (AI Navigation icon in the Scene view toolbar) to see the walkable area in blue.
  2. NavMeshAgent (component, built-in) — put it on the enemy. Key settings: Speed / Angular Speed / Acceleration (how it moves), Radius/Height (how much room it needs), Stopping Distance (how close counts as "arrived" — the kit's patrol uses this).
  3. NavMeshData (asset) — the baked result. It must exist for agents to work; "Failed to create agent because there is no valid NavMesh" means you forgot to bake (or the agent spawned off the mesh).
The kit bakes for you

Create 3D NavMesh Enemy Demo adds a NavMeshSurface to its Level object, bakes it, and saves the data asset — before spawning the player and enemy so their capsules don't get baked into the map as obstacles (a real gotcha when you bake by hand: set moving things to not be included, or bake before placing them).

Why the kit's editor script looks odd

EnemyKitSetup.cs calls NavMeshSurface via reflection rather than using Unity.AI.Navigation;. That's purely defensive: it keeps the kit compiling even in a project where the package isn't installed. In your own project code, use the normal using — it's shown in a comment right at the bake method.

Settings worth teaching

Checklist

Next: 03 - The 3D Enemy