# Terrain
The built-in Terrain system (`Terrain`, `TerrainData`, `TerrainCollider`, `TerrainLayer`) plus the optional **Terrain Tools** package, taught as a *level design* tool: you sculpt a world so the player can read it, then script the parts that should be repeatable (height shaping, splat rules, tree scatter, sightline checks).
**Target:** Unity **6000.5+** (Unity 6.5), Universal Render Pipeline. For a Quest 2 headset build use **Unity 6.3 LTS (6000.3.27f2+)** - see [[0.Choosing a Unity Version]] - and read part 6 before you commit to Terrain on standalone VR.
> [!warning] Code not compiled
> None of the C# in this series has been compiled or play-tested in Unity. API names were checked against the 6000.5 Scripting Reference on 2026-11-10 (links in each part and in Sources below). Treat every script as a careful first draft: paste it, let the compiler talk, fix, then commit.
> [!note] Verification status
> **Verified (2026-11-10):** Terrain Tools **5.3.3** is the version "released for Unity Editor version 6000.5" on the 6000.5 package page; its changelog says 5.3.2 migrated Mono APIs to CoreCLR-compatible APIs for 6000.5+. `TerrainData` / `Terrain` members used here (`SetHeights`, `SetHeightsDelayLOD`, `SyncHeightmap`, `GetSteepness`, `GetInterpolatedHeight`, `GetInterpolatedNormal`, `SetAlphamaps`, `SetDetailLayer`, `SetTreeInstances`, `SampleHeight`, `drawInstanced`, `heightmapPixelError`, `basemapDistance`, `ignoreQualitySettings`, `CreateTerrainGameObject`) exist on the 6000.5 Scripting Reference. Heightmap resolution clamps to 33, 65, 129, 257, 513, 1025, 2049 or 4097 (TerrainData docs).
> **Not verified:** exact draw-call/pass cost of more than four Terrain Layers per tile in URP on Quest (measure with the Frame Debugger), and how detail density integers map to visible grass in each `DetailScatterMode` (the docs only say the meaning "depends on which DetailScatterMode is set").
## Parts
| # | Note | Covers |
|---|---|---|
| 1 | [[1. Terrain Setup and Heightmaps]] | Creating tiles, size vs resolution, Terrain Tools 5.3.3, sculpting, RAW import, a procedural shaper script |
| 2 | [[2. Terrain Layers and Splat Rules]] | TerrainLayer assets, URP Terrain Lit, height/slope auto-splat script |
| 3 | [[3. Trees Details and the Flyweight]] | Tree and detail prototypes, rule-based tree scatter, grass from splat, Flyweight pattern |
| 4 | [[4. Level Design with Terrain - Landmarks and Sightlines]] | Level Up! level design applied to terrain; landmark sightline checker; snap-to-terrain tool |
| 5 | [[5. Runtime Terrain Queries and Deformation]] | Surface type under a point (footsteps), runtime TerrainData clone, crater deformation |
| 6 | [[6. Terrain Performance Mobile and Quest]] | Pixel error, basemap, instancing, details/trees budgets, Quality Settings overrides, Quest notes |
| 7 | [[7. Terrain Pitfalls]] | The mistakes that cost the most time |
## Suggested path
1. Read part 1 and build a 1 km tile by hand (10 minutes of sculpting teaches more than any script).
2. Do part 4 *before* parts 2-3: decide where the landmark, the spawn and the route go, then texture and plant to support those decisions.
3. Parts 2-3 automate texturing and planting so you can iterate on the layout without repainting.
4. Part 5 if gameplay touches the ground (footsteps, explosions). Part 6 before any mobile/Quest build.
## Design lens (Level Up!)
Scott Rogers' level design chapter (Level 9 in [[Level Up! (Review)]]) frames levels as theme parks: show the destination early, guide with **landmarks** and **sightlines**, control pacing, hide the backstage. Terrain is where that matters most, because open ground gives the player no corridors to follow. Part 4 turns those ideas into tools you can run in the editor: a landmark sightline checker that tells you *from where* the player can actually see the goal, and a coverage percentage you can track as you sculpt. The character's movement metrics (Level 5) set slope limits for walkable ground - keep your max walkable slope consistent with the Agent Type in [[NavMesh in Unity 6 (AI Navigation 2.x)]] and the controller in [[Character Controllers]].
## Patterns used (Game Programming Patterns)
- **Flyweight** - trees and grass are the book's own example: one shared prototype (mesh, material) and thousands of tiny per-instance records (`TreeInstance`: position, scale, rotation, color). Part 3. See [[Game Programming Patterns (Review)]].
- **Spatial Partition** - the terrain heightmap *is* a regular grid; sampling it by index is a spatial partition lookup (part 5).
- **Dirty Flag** - `SetHeightsDelayLOD` + `SyncHeightmap` is a dirty flag: edit many times, rebuild LOD once (part 5).
- **Type Object** - the splat rules and quality profiles are data assets, not code branches (parts 2 and 6).
## Related (existing)
- [[Lighting and Baking]] - baking GI over terrain; [[6.Mobile and Meta Quest Considerations]] for the VR lighting budget
- [[NavMesh in Unity 6 (AI Navigation 2.x)]] - bake on terrain, Agent Type max slope = your metrics
- [[Character Controllers]] and [[5. Gray-Box Metrics Gym]] - slope and step limits come from here
- [[4. Footsteps and Surface Audio]] - consume the surface query from part 5
- [[URP Shaders and Shader Graph]] - custom terrain-adjacent shading; [[HDRP Essentials]] if you go high-end
- [[Tilemaps and Tilesets]] - the 2D cousin (painting a grid of shared tiles)
- [[Custom Inspectors and Editor Tooling]] - turn the context-menu tools here into proper editor windows
- [[Particle Systems and Layered Effects]] / [[VFX Graph]] - dust, landmark beacons, explosions that deform the ground
- [[2. Git LFS]] - TerrainData assets are large binaries; track `*.asset` terrain data and `*.raw` heightmaps with LFS
- [[DOTS]] - when you need thousands of agents walking on the terrain
## Sources
- Terrain Tools package page, 6000.5 (version 5.3.3 released for 6000.5): https://docs.unity.com/en-us/engine/6000.5/manual/packages-list/packages-all/pack-safe/com-unity-terrain-tools
- Terrain Tools 5.3 manual: https://docs.unity3d.com/Packages/
[email protected]/manual/index.html
- Terrain Tools changelog (5.3.3, 2026-08-19): https://docs.unity3d.com/Packages/
[email protected]/changelog/CHANGELOG.html
- Terrain manual (6000.5): https://docs.unity3d.com/6000.5/Documentation/Manual/script-Terrain.html
- Terrain settings reference: https://docs.unity3d.com/6000.5/Documentation/Manual/terrain-OtherSettings.html
- `TerrainData` API: https://docs.unity3d.com/6000.5/Documentation/ScriptReference/TerrainData.html
- `Terrain` API: https://docs.unity3d.com/6000.5/Documentation/ScriptReference/Terrain.html
- URP Terrain Lit shader: https://docs.unity3d.com/6000.5/Documentation/Manual/urp/shader-terrain-lit.html
- Flyweight chapter: https://gameprogrammingpatterns.com/flyweight.html