Using the Terrain Tools in Unity

Learn to create and manage a wide range of terrains in your apps by using Unity’s powerful Terrain Tools and the all new Terrain Toolbox API. By Mauro Fuentes.

3.7 (3) · 2 Reviews

Download materials
Save for later
Share
You are currently viewing page 2 of 5 of this article. Click here to view the first page.

Creating Your First Terrain

The options section is the last on the page, so it may seem strange to start with it. However, TerrainData Directory is where Unity will store all of the terrain assets you create. You’ll want to set this up first to make sure everything is saved in the same place.

Click the Ellipsis icon. In Explorer, select the existing folder, Terrains, from the path: Using the Terrain Tools in Unity Starter/Assets/RW/Terrains.

Next, in the General section, enter the following values:

  • Total Terrain Width(m): 8000
  • Total Terrain Length(m): 8000
  • Terrain Height(m): 3000
  • Group Settings ▸ Tile Height Resolution: 1025

You’ll learn more about these options in the next section.

Finally, set the material to use for the generated terrain. In the General section, under Group Settings, find the Material Override and select the TerrainLit material from Packages/Universal RP/Runtime/Materials, like this:

How to recover the TerrainLit material for the terrain

Now, click Create.

Lo and behold… congratulations on your first terrain!

Looking Over Your First Terrain

The new terrain looks like this:

A Terrain consisting of a black background with a gray trapezoid on it

Notice that there are three toggles at the bottom of the Options section:

The three toggles in the Options menu

Here’s what they do:

  • TerrainData Name Enable Guid: Appends a GUID to the name of the terrain, ensuring each terrain asset is named uniquely.
  • Replace Terrains: Keeps the TerrainData file intact, but updates the values and mesh.
  • Enable Auto Generate Lighting: Enables that option in the Lighting tab by default.

Now, for the next step in the tutorial!

Understanding the General Section

The General section might seem daunting at first sight, but if you scan the text, you’ll notice it’s just a specialized Transform Component.

You’ve already used Height, Width and Length components. They do just what they describe — set the height, width and length of the terrains you create.

Among others, Tiles and Grouping ID are new features.

Grouping ID is just a number for making groups of terrains that are located near each other. Imagine, for instance, that you need to create distant mountains. You’d create a new group to keep those mountains together, and to ease distancing them from your other terrain in the scene.

Keep an eye on Tile Height Resolution. Very often, people overexaggerate the polygon count. In this tutorial, you’ll use 1025.

Also, for brevity, this tutorial will abbreviate Tile Height Resolution as THR or, simply, Resolution.

Note: The available values for THR may look strange at first, but these are all just (power of 2) + 1. Working in powers of 2 is common when dealing with textures and tiles, as it helps these values fit nicely into a computer’s memory.

What? You don’t believe people overexaggerate? Feel free to change the THR values and see for yourself!

THR 33:
A picture showing a wireframe version of a terrain at 33 THR

THR 65:
A picture showing a wireframe version of a terrain at 65 THR

THR 129:
A picture showing a wireframe version of a terrain at 129 THR

THR 257:
A picture showing a wireframe version of a terrain at 257 THR

THR 513:
A picture showing a wireframe version of a terrain at 513 THR

If you spend too many triangles on terrain, your computer won’t have any time left over to render your other models, like your wizards and hobbits. As a rule of thumb, if your mesh looks solid green and you can’t see its triangles, you probably have the resolution too high and can lower it down!

Now, you’ll learn about another cool feature.

Introducing the Cool New Gizmo Feature

At last! Unity added a terrain gizmo. Activate it by clicking the checkbox next to Gizmo in the Create New Terrain tab.

How to activate the terrain Gizmo

With this tool, it’s easy to check the boundaries and overall height of your terrains. It also gives you an intuitive idea of the extension a terrain has. Unfortunately, you can only use it on one terrain at a time.

What’s it good for? For example, say you want to raise your overall terrain height by 50%. The gizmo will clearly show you both positive and negative headroom, like this:

Gizmo tool showing the headroom of a terrain

Take some time to play around with all the features. Create as many terrains as you want. When you’re ready, go to the next part… where the real fun begins.

Importing Heightmaps

Heightmaps are among the most important and fun tools at your disposal.

Before you begin, switch to Scene 1, located in RW/Scenes/Scene 1.

You’ll notice every folder has a number. That’s because they follow an asset-oriented pattern that relies on instances of objects, so it’s useful to know which scene they belong to.

Now, go to the Terrain Toolbox. Select the Create New Terrain tab and click the Import Heightmap toggle to activate it.

Import Heightmap box of the Toolbox

Inside Scene 1, there’s a heightmap that’s ready for you to use.

How to set up the heightmap to a 16 bit red channel

Note: Although the heightmap is a grayscale image, Unity uses the red channel for it. It’s important to make sure to verify its format in the inspector before proceeding. Otherwise, it won’t work.

Now, make sure the texture format of Heightmap 1 is R 16 bit, then drag and drop it inside the empty box on the Toolbox’s Import Heightmap section (the Select Texture field).

How to drag and drop a texture to the Heightmap in the Toolbox

Now, go back to the General section and use these values:

  • Width: 8000
  • Length: 8000
  • Height: 2500
  • THR: 1025

Finally, take a deep breath and press Create. Behold!

A mountain created from heightmaps

Note: If you don’t see the whole mountain, tweak the values of the camera on the Scene View.

Your Hierarchy will now have a parent GameObject showing the terrain group and the terrain you’ve just created as a child.

Hierarchy of the Terrain GameObject

Look at the name and you’ll see it’s a little… long. Again, Unity appended this name with a GUID to keep your terrain names unique. For the sake of this tutorial, rename it to Terrain_1.

Select it and you’ll see the same old Terrain component in the inspector along with Terrain Data.

As a mental note, Terrain Data is an asset. It’s inside your project, located in the TerrainData Directory you selected earlier. Click it so you can rename it to Terrain_1, too.

Renaming the Terrain GameObject and the Data

Is that it? Of course not. Just for a little taste, do this:

  1. Select the Terrain_1 GameObject.
  2. Go to the Terrain component.
  3. Select the Paint Terrain tab.
  4. In the first dropdown below the row of tabs, select Paint Texture.
  5. Find the Layers section.
  6. Click Add Layer.
  7. Find TextureMountainLayer 1 and select it.

Boom!

This PNG explains how to assign a layer texture to terrain

Wait, it doesn’t look so good? Gotcha. Go to the Terrain Settings tab in the same component and adjust Base Map Distance to maximum.

This GIF shows how to adjust the Base Map Distance.

This is the final result:

an image showing a mountain with the texture applied

And there you go. Next, you’ll take a look at the Terrain Settings tab.