0
0
Unityframework~10 mins

Terrain system basics in Unity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Terrain system basics
Start Unity Project
Create Terrain Object
Set Terrain Size & Resolution
Modify Terrain Height
Apply Textures & Details
Add Trees & Objects
Test & Adjust Terrain
Save Scene & Project
This flow shows the basic steps to create and customize a terrain in Unity, from starting a project to saving the final terrain.
Execution Sample
Unity
Terrain terrain = Terrain.CreateTerrainGameObject(new TerrainData()).GetComponent<Terrain>();
terrain.terrainData.size = new Vector3(500, 100, 500);
float[,] heights = new float[513, 513];
heights[256, 256] = 0.5f;
terrain.terrainData.SetHeights(0, 0, heights);
This code creates a terrain, sets its size, modifies the height at the center, and applies the height changes.
Execution Table
StepActionVariable/Property ChangedValue After ActionNotes
1Create Terrain GameObjectterrainTerrain object createdTerrain object is ready to use
2Set terrain sizeterrain.terrainData.size(500, 100, 500)Terrain dimensions set (width, height, length)
3Create heights arrayheights513x513 float array initialized with 0All heights start flat at 0
4Set center heightheights[256,256]0.5Raise center point to half max height
5Apply heights to terrainterrain.terrainData.SetHeightsHeights updatedTerrain surface updated with new heights
💡 All steps complete, terrain created and modified successfully
Variable Tracker
VariableStartAfter Step 3After Step 4Final
terrainnullTerrain object createdTerrain object createdTerrain object created
terrain.terrainData.size(1000, 600, 1000) default(500, 100, 500)(500, 100, 500)(500, 100, 500)
heightsnull513x513 array of 0513x513 array with center 0.5513x513 array with center 0.5
Key Moments - 3 Insights
Why do we use a 2D array for heights?
Because the terrain surface is a grid of points, each with a height value, so a 2D array matches the terrain layout (see Step 3 and 4 in execution_table).
What does setting terrain.terrainData.size do?
It changes the physical size of the terrain in the world (width, height, length), not just the height values (see Step 2).
Why do we call SetHeights after changing the array?
Because modifying the array alone doesn't update the terrain; SetHeights applies the changes to the terrain surface (see Step 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the height value at the center point after Step 4?
A1.0
B0
C0.5
DUndefined
💡 Hint
Check the 'Value After Action' column for Step 4 in the execution_table.
At which step is the terrain size changed?
AStep 2
BStep 1
CStep 4
DStep 5
💡 Hint
Look for 'Set terrain size' in the Action column of execution_table.
If we skip calling SetHeights, what happens to the terrain?
ATerrain height changes are visible
BTerrain remains flat
CTerrain size changes
DTerrain is deleted
💡 Hint
Refer to Step 5 notes in execution_table about applying height changes.
Concept Snapshot
Unity Terrain Basics:
- Create terrain with Terrain.CreateTerrainGameObject()
- Set size via terrain.terrainData.size
- Modify heights using a 2D float array
- Apply heights with terrain.terrainData.SetHeights(x, y, heights)
- Changes update the visible terrain surface
Full Transcript
This visual execution shows how to create and modify a terrain in Unity. First, a terrain object is created. Then, its size is set to control the physical dimensions. A 2D array of floats represents the height map, where each value controls the height at a grid point. We modify the center height to raise it. Finally, we apply these heights to the terrain using SetHeights, which updates the visible terrain surface. This step-by-step trace helps beginners see how terrain data changes affect the final terrain.