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 3 of 5 of this article. Click here to view the first page.

Exploring the Terrain Settings Tab

The Terrain Settings tab on the Toolbox is exactly the same as the Terrain Settings tab on the Terrain component… but you can only apply the former, as you’ve read before, to all terrains.

So this…

Terrain Settings Tab

Is the same as this:

Terrain Settings in the inspector

The difference is that, now, you can apply changes locally to each terrain, through the Terrain component, or globally to all terrains in the scene, through the Terrain Toolbox.

If you want to know more about basic settings, please also check this amazing tutorial by Brian Moakley Introduction to Unity: Terrain Generation.

Terrain Utilities Tab

Welcome to one the most important tools. Terrain Utilities is where the Toolbox really exploits its “one-for-all” power.

As a quick introduction, this tab allows you to safely erase terrains. No more lost terrains cluttering your project. Also, you can manage all your layers and splatmaps from here.

Looking at the Terrain Edit Section

In the past, it was common to forget about your terrains and end up having lots of unused files. The worst-case scenario was to erase an important terrain. As you know, they’re assets, so if you erase them… there’s no undo.

Finally (!), you can get rid of unneeded terrains safely. Just select a terrain and click Erase. Unity will take care of the TerrainData for you.

Reviewing the Terrain Layers Section

To begin afresh, open Scene 2. It’s your turn to practice. Your goal is to repeat the process of creating a terrain using a heightmap texture.

Use the values below in the General settings, then add the heightmap located in Assets/RW/Scenes/Scene 2/Heightmap 2. As always, remember to rename the GameObject and the linked TerrainData object, like you did before. This helps you keep track of them.

  • Width: 8000
  • Length: 8000
  • Height: 2500
  • Resolution: 1025
  • Base Map Distance: 20000

How to create a mountain using a heightmap.

Remember, practice makes perfect!

Next, it’s time to look at terrain layers.

Examining the Layers

Before you continue, try to wrap your head around this: A Terrain Layer is an asset. It’s a file in your project that holds textures to paint Terrains. Textures are also assets. Terrains are assets. Palettes are assets. Material Palettes are assets. You are an asset. The writer of this tutorial is an asset. Ray Wenderlich himself is an asset… the whole world is an asset! :]

Joking aside, you have to be extra careful about which asset’s values you’re changing. Otherwise, if you’re looking at a global asset, you’ll end up changing global values. The solution to this is to learn to properly use and edit Layers.

Navigate to Assets/RW/Scenes/Scene 2/TerrainLayers 2 to explore the layers you need for this part of the tutorial.

You can always create new layers by right-clicking in the Unity Editor window and selecting Create and then Terrain Layer. You’ll then add the relevant Diffuse, Normal Map and Mask Map textures.

Now that you have an overview of layers, you can create palettes.

Creating Palettes

Layers in the Toolbox work exactly as they do in popular programs like GIMP, Substance Painter and Photoshop. They stack on top of each other and blend according to alpha values:

How layers stack to make a texture

A palette is just a group of layers. It’s a key element in the hierarchy of tools in your toolbox:

How textures, layers and palettes relate to each other

To create one, go back to the Toolbox, navigate to Terrain Utilities and, in the Terrain Layers section, click the Plus button to add a new layer.

How to create a new palette

Select snow 2 from the assets you just saw, then drag and drop it into your new layer slot.

Order matters here (the top layer will be rendered over all of the others), so repeat this process with dirt 2, then moss 2, and finally rock 2 to complete your palette.

This GIF shows how to add four layers to the Terrain Layers to create a New Palette

Finally, press the Save button in the top right of the Terrain Layers section to save this group of layers as a palette preset. You will be prompted to create a new palette; press OK. For easy reference, you can save it to the same path as the layers: Assets/RW/Scenes/Scene 2/TerrainLayers 2. Name this palette something comfortable, like PaletteScene 2.

Adding the Palette to the Terrain

Done! Now, you’re ready to add the palette to your terrain. Select your terrain in the Scene view and click the Add to Terrain button.

Where the Add to Terrain button is

Your mountain will now be snow-tinted, like this:

A mountain tinted white

Note: Remember, the order of layers in a palette matters. You can play around with changing this order to see how the terrain textures change.

Next, you’ll learn how to use splatmaps to make this mountain more awesome!

Introducing Splatmaps

A splatmap is a texture that uses its own color channels as layer masks. Normally, a splatmap uses four channels: green, blue, red and alpha.

That means, instead of painting snow, rocks and grass directly, you paint green, blue, red and alpha. This decouples the painting process from the chosen textures.

Suppose tomorrow, you decide to change the snow texture to… er… lava. You’d only need to change the texture, not the paint strokes.

In practical terms, you could have:

  • Snow on the green channel.
  • Rocks on the blue one.
  • Grass on the red one.
  • Dry grass on the alpha.
Note: URP supports up to four layers per splatmap.

So, how can you apply a splatmap to your mountain?

Applying Splatmaps

Inside your toolbox, go back to Terrain Utilities and locate Terrain Splatmaps.

Where the Terrain Splatmaps tab is

Click the Plus button to add a new splatmap, just like you did to add a new layer. Drag and drop RW/Scenes/Scene 2/SplatMap 2 into your new splatmap slot, then click Apply to Terrain.

One more step for the magic: Make sure your Terrain object is selected in the Hierarchy, then click Apply to Terrain… and marvel!!

How to apply a splatmap to a terrain with layers.

To recap, each layer in your palette corresponds to a color in the splatmap: Unity paints snow everywhere it’s red, moss everywhere it’s blue, etc. Once again, order matters here. Feel free to reorder the layers in your palette to swap the channels in your splatmap.

The final result:
A mountain after applying splatmaps to it