Hi, I wonder if anyone have been able to create a terrain from script? I've tried lots of different approaches and read all the posts on the forum but either unity crashes silently or it complains about the terrain not being connected properly. Some examples: This results in "Terrain not correctly connected to a terrainData object". Code (csharp): GameObject g = new GameObject(); Terrain t = (Terrain)g.AddComponent("Terrain"); This crashes the editor. Code (csharp): TerrainData d = new TerrainData(); GameObject g = Terrain.CreateTerrainGameObject(d); This results in "Exception: X or Y base out of bounds. Setting up to 513x513 while map size is 0x0" Code (csharp): TerrainData d = new TerrainData(); float[,] height_data = new float[513, 513]; d.SetHeights(0, 0, height_data); GameObject g = Terrain.CreateTerrainGameObject(d); This crashes the editor. Code (csharp): TerrainData d = new TerrainData(); d.Init(1024, 1024, 512); d.size = new Vector3(1000, 10, 1000); float[,] height_data = new float[513, 513]; d.SetHeights(0, 0, height_data); GameObject g = Terrain.CreateTerrainGameObject(d); Cheers, //Fredrik
As far as i know the TerrainData needs to be stored as an asset Create your terrain in the normal way, so that the TerrainData.asset appears in you project view. You can then delete it from you scene if you like, and then use Terrain.CreateTerrainGameObject referencing the TerrainData asset