I’ve spent hours trying to figure out how to add run-time terrain objects. I briefly succeeded in producing a small terrain that appeared in the right spot, but during my attempt to find a way to change the heightmap resolution the terrain no longer showed up, and I haven’t been able to get it to display again after figuring out how to change the resolution.
Here are the crucial parts of my code (from a function that generates the terrain at runtime). I’m hoping someone can tell me what I’m doing wrong:
var TerrainChunk1Data: TerrainData = new TerrainData();
TerrainChunk1Data.heightmapResolution = TerrHtMapRes;
TerrainChunk1Data.size = Vector3(TerrainChunkWidth,TerrainChunkHeight,TerrainChunkLength);
var TCHtMap:float[,] = new float[TerrHtMapRes,TerrHtMapRes];
//fill in the heighmap with a test pattern of all 5s
for (var y:int=0; y<TerrHtMapRes;y++)
{
for (var x:int=0; x<TerrHtMapRes;x++)
{
TCHtMap[y,x] = 5.0;
}
}
TerrainChunk1Data.SetHeights(0, 0, TCHtMap);
var TerrainChunk1Obj = Terrain.CreateTerrainGameObject(TerrainChunk1Data);
TerrainChunk1Obj .transform.position = Vector3(-13,-15,-107);