Challenge - 5 Problems
Terrain Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Unity C# code snippet?
Consider the following code that modifies a terrain's height at a specific point. What will be the height value printed in the console?
Unity
using UnityEngine; public class TerrainTest : MonoBehaviour { void Start() { Terrain terrain = GetComponent<Terrain>(); float[,] heights = terrain.terrainData.GetHeights(0, 0, 1, 1); heights[0, 0] = 0.5f; terrain.terrainData.SetHeights(0, 0, heights); float newHeight = terrain.terrainData.GetHeight(0, 0); Debug.Log(newHeight); } }
Attempts:
2 left
💡 Hint
Remember that terrain heights are normalized and scaled by terrain size.
✗ Incorrect
The GetHeights and SetHeights methods use normalized values between 0 and 1. The actual height returned by GetHeight is scaled by the terrain's height in meters, so the output depends on the terrain's height property.
🧠 Conceptual
intermediate1:00remaining
Which Unity component is required to display a terrain in a scene?
You want to add a terrain to your Unity scene. Which component must be attached to the GameObject to render the terrain?
Attempts:
2 left
💡 Hint
This component handles terrain rendering and collision.
✗ Incorrect
The Terrain component is specifically designed to render terrains and manage their data in Unity.
🔧 Debug
advanced2:00remaining
Why does this terrain height modification code not change the terrain?
Look at this code snippet that tries to raise the terrain height at (10,10) by 0.1. Why does the terrain not change visually?
Unity
Terrain terrain = GetComponent<Terrain>(); float[,] heights = terrain.terrainData.GetHeights(0, 0, terrain.terrainData.heightmapResolution, terrain.terrainData.heightmapResolution); heights[10, 10] += 0.1f; // Missing code here
Attempts:
2 left
💡 Hint
Modifying the array alone does not update the terrain.
✗ Incorrect
You must call terrain.terrainData.SetHeights to apply changes to the terrain. Without this, the terrain remains unchanged.
📝 Syntax
advanced2:00remaining
Which code snippet correctly sets a 3x3 flat area of height 0.2 on a terrain?
You want to set a 3x3 area starting at (5,5) to height 0.2. Which code snippet does this correctly?
Attempts:
2 left
💡 Hint
The heights array size must match the area size, and indices inside the array start at 0.
✗ Incorrect
The SetHeights method expects a 2D array sized to the area being set, with indices starting at 0. Option C correctly creates a 3x3 array and fills it with 0.2, then sets it at (5,5).
🚀 Application
expert3:00remaining
How to efficiently raise terrain height in a circular area using Unity's Terrain API?
You want to raise the terrain height smoothly in a circular area with radius 10 around point (x=50, z=50). Which approach is best to achieve this efficiently?
Attempts:
2 left
💡 Hint
Minimize the area you read and write to improve performance.
✗ Incorrect
Reading and writing only the needed square area covering the circle reduces processing time and memory use. Looping through that smaller area and applying height changes is efficient.