- Home /
Error while trying to access a Terrain's terrainData.
Looking at the documentation for the [Terrain][1], I can see that there is a variable called terrainData that stores all of the information regarding heightmaps, which I want to access. However, when calling it from a script, I get the error that states that Terrain does not contain a definition for terrainData. Specifically:
Assets/GameAssets/Scripts/TerrainDeformer.cs(48,24): error CS1061: Type 'Terrain' does not contain a definition for 'terrainData' and no extension method 'terrainData' of type 'Terrain' could be found (are you missing a using directive or an assembly reference?)
Why am unable to access this variable? Here's some simple example code where it doesn't work:
using UnityEngine;
using System.Collections;
public class Terrain : MonoBehaviour
{
void Start ()
{
Terrain t = new Terrain();
print(t.terrainData);
}
}
Thank you! [1]: http://docs.unity3d.com/Documentation/ScriptReference/Terrain.html
Answer by robertbu · Jun 21, 2013 at 01:49 AM
You have a scoping issue. You've named the class in this file Terrain which is overriding Unity's Terrain class. Rename this class so something like 'MyTerrain' and it should work.