Legacy Documentation: Version 5.4
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

TerrainData

class in UnityEngine

/

Inherits from: Object

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

The TerrainData class stores heightmaps, detail mesh positions, tree instances, and terrain texture alpha maps.

The Terrain component links to the terrain data and renders it.

Variables

alphamapHeightHeight of the alpha map.
alphamapLayersNumber of alpha map layers.
alphamapResolutionResolution of the alpha map.
alphamapTexturesAlpha map textures used by the Terrain. Used by Terrain Inspector for undo.
alphamapWidthWidth of the alpha map.
baseMapResolutionResolution of the base map used for rendering far patches on the terrain.
detailHeightDetail height of the TerrainData.
detailPrototypesContains the detail texture/meshes that the terrain has.
detailResolutionDetail Resolution of the TerrainData.
detailWidthDetail width of the TerrainData.
heightmapHeightHeight of the terrain in samples (Read Only).
heightmapResolutionResolution of the heightmap.
heightmapScaleThe size of each heightmap sample.
heightmapWidthWidth of the terrain in samples (Read Only).
sizeThe total size in world units of the terrain.
splatPrototypesSplat texture used by the terrain.
thicknessThe thickness of the terrain used for collision detection.
treeInstanceCountReturns the number of tree instances.
treeInstancesContains the current trees placed in the terrain.
treePrototypesThe list of tree prototypes this are the ones available in the inspector.
wavingGrassAmountAmount of waving grass in the terrain.
wavingGrassSpeedSpeed of the waving grass.
wavingGrassStrengthStrength of the waving grass in the terrain.
wavingGrassTintColor of the waving grass that the terrain has.

Public Functions

GetAlphamapsReturns the alpha map at a position x, y given a width and height.
GetDetailLayerReturns a 2D array of the detail object density in the specific location.
GetHeightGets the height at a certain point x,y.
GetHeightsGet an array of heightmap samples.
GetInterpolatedHeightGets an interpolated height at a point x,y.
GetInterpolatedNormalGet an interpolated normal at a given location.
GetSteepnessGets the gradient of the terrain at point (x,y).
GetSupportedLayersReturns an array of all supported detail layer indices in the area.
GetTreeInstanceGet the tree instance at the specified index. It is used as a faster version of treeInstances[index] as this function doesn't create the entire tree instances array.
RefreshPrototypesReloads all the values of the available prototypes (ie, detail mesh assets) in the TerrainData Object.
SetAlphamapsAssign all splat values in the given map area.
SetDetailLayerSets the detail layer density map.
SetDetailResolutionSet the resolution of the detail map.
SetHeightsSet an array of heightmap samples.
SetHeightsDelayLODSet an array of heightmap samples.
SetTreeInstanceSet the tree instance with new parameters at the specified index. However, TreeInstance.prototypeIndex and TreeInstance.position can not be changed otherwise an ArgumentException will be thrown.

Inherited members

Variables

hideFlagsShould the object be hidden, saved with the scene or modifiable by the user?
nameThe name of the object.

Public Functions

GetInstanceIDReturns the instance id of the object.
ToStringReturns the name of the game object.

Static Functions

DestroyRemoves a gameobject, component or asset.
DestroyImmediateDestroys the object obj immediately.
DontDestroyOnLoadMakes the object target not be destroyed automatically when loading a new scene.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsOfTypeReturns a list of all active loaded objects of Type type.
InstantiateReturns a copy of the object original.

Operators

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.