I’m having trouble using the (hopefully faster) API that sets heights on a Terrain object. Some code examples would be really wonderful on how to go about it. No matter what I have tried, the resulting heights just get set far above the maximum height for the Terrain, and are all flat. Here’s some example code:
Terrain terrainComp = forTerrainComps[tx, ty];
var renderTex = terrainComp.terrainData.heightmapTexture;
Texture2D tempTex = new Texture2D(renderTex.width, renderTex.height, UnityEngine.Experimental.Rendering.GraphicsFormat.R16_UNorm, UnityEngine.Experimental.Rendering.TextureCreationFlags.None);
var rawData = tempTex.GetRawTextureData<short>();
for (int i = 0; i < rawData.Length; i++)
{
rawData[i] = 0;
}
Graphics.CopyTexture(tempTex, renderTex);
terrainComp.terrainData.UpdateDirtyRegion(0, 0, renderTex.width, renderTex.height, true);
This code definately does something - it makes the terrain heights be placed at least twice as high as the maximum height that the terrain has specified (similar to this post , but I wasn’t able to ever get it working). Note that the target texture is being set to all zeros, but whatever numbers i try in there I get the same result.
My ultimate goal is to use NativeArrays that are filled via Burst jobs, as requested here.
I also tried using the TerrainPaintUtility, but with essentially the same results, except that I have no idea what to pass in for ‘boundsInTerrainSpace’, as terrain space isn’t defined, and so it only impacts a subset of the terrain. Also, as that API includes things like ‘undo tags’, it makes me think it’s not supposed to be used at runtime, but rather only in the editor.
I note that there are more APIs available in 2019.2 ( as detailed here ), but we’re unable to go to 2019.1 or .2 due to this issue.