Unity 5.6—How to create TerrainData with a heightmap via C# script?


I’m trying to load tiled terrains at runtime, and I don’t want to make prefabs because it is too much work. I have the heightmaps and textures exported from worldmachine. The heightmaps are in raw16 format and some other formats are available.

I have searched the Script API and some discussions in this forum. It turns out that TerrainData.SetHeights() API only accepts a float height array as input. It seems there’s no way to create a terrain directly from the heightmap. So I’m asking how to deal with this situation?

Someone converts the heightmap to binary file and loads it as a TextAsset, but there’s no detail. So I’m thinking about the exporting format of heightmap, so that it can be read via C# script. It would be great if someone could share a solution.


@fc2012 Take a look at this answer how to use a script to import terrain .raw? - Questions & Answers - Unity Discussions