- Home /
Question by
vandrewm · Feb 03, 2011 at 02:26 AM ·
terrainterraindata
Terrain class - How do I reference it?
I'm trying to load TerrainData from resources dynamically and set Terrain.SetNeighbors. However, in order to use SetNeighbors I need references to a "Terrain" object, which I cannot figure out how to obtain.
I load the TerrainData in, create it as a GameObject, and render it. Nowhere in those steps do I ever deal with a Terrain object. So how do I refer to the "Terrain" of this GameObject so I can plug it into "SetNeighbors"?
TerrainData terraindata = (TerrainData)Resources.Load("Terrain/TerrainDataName");
GameObject terrain = Terrain.CreateTerrainGameObject(terraindata);
terrain.transform.position = new Vector3(0,0,0);
terrain.AddComponent("MeshRenderer");
terrain.renderer.enabled = true;
Help would be much appreciated.
Comment
Best Answer
Answer by vandrewm · Feb 09, 2011 at 03:16 AM
This seemed to work:
Terrain myTerrain = terrain.GetComponent<Terrain>();
Your answer
![](https://koobas.hobune.stream/wayback/20220613102541im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Inserting heights in TerrainData 2 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Tracking information across terrain 1 Answer
generate terrain by script 0 Answers