Setting up and using Navigation in Unity

Jon Jenkins
2 min readJun 23, 2021

Unity gives us basic pathfinding right out of the box. We just need to set it up. Here I will go through the steps of getting basic navigation up and running for a game object. Here we want our game object to move to the point on the screen where we click, avoiding obstacles as necessary.

The first thing we need to do is to add a navmeshagent component to our game object, shown below:

The next thing we need to do is make sure we have a proper navigation mesh set up on our ground that we want to traverse. This is done by setting the ground to static and then baking it. The baking function is accessed via the navigation menu. This is done like so:

We now have basic navigation set up. However, we aren’t quite there yet with what we want. As you can see below when I click on the ground, our capsule moves straight to the point I clicked on and passes straight through the cars in the scene. We obviously don’t want that.

Fixing this is quite simple. All we need to do is set the cars to static and then bake the scene again:

Now we have our final product. Here you can see the cylinder will now navigate the scene and properly avoid the cars that are in its path.

Under the hood, Unity uses the A* pathfinding algorithm to traverse the scene. Interestingly, this algorithm was first developed in 1968 for robot pathfinding. Read more about Unity’s navigation system here:

Unity — Manual: Inner Workings of the Navigation System (unity3d.com)

--

--