Hi guys, I am lost with the new Terrain 2019+ APIs, layers and textures

Is there a simple example script from start to end, that can load textures from resource files and set alpha maps using the APIs in unity 2019/2020?

The documentation out there is very poor, frustrating, and confusing me, no simple example

public class myTerrainScript1 : MonoBehaviour
{
private TerrainData _terrainData;
private float[,] _heights; // [0,1] normalized heights
SplatPrototype[ ] terrainTexture;
TerrainLayer[ ] terrainLayers;

// Start is called before the first frame update
void Start()
{
Debug.Log(“Start()”);

// terrainData stores the heightmaps of the terrain
// textures, trees and other important terrain details.
_terrainData = terrain.terrainData;
Debug.Log(“Terrain Size world Coordnates:\n” +
“X axis = terrain width =” +
_terrainData.size.x +
" Z axis = terrain length =" +
_terrainData.size.z + " Y axis = terrain height =" +
_terrainData.size.y);

// Useful for application
string sAppDataPath = Application.persistentDataPath;
string sAppStreamingAssetsPath = Application.streamingAssetsPath;
DirectoryInfo dIassets = Directory.GetParent(sAppStreamingAssetsPath);
string sAppAssetsPath = dIassets.FullName;
string texturePath = sAppAssetsPath + @“\SurfaceTextures”; //Materials";
string textureFile = texturePath + @“\MudRockyNormals”;

// string textureFile = “MudRockyNormals”;
terrainTexture = new SplatPrototype[6];
terrainLayers = new TerrainLayer[6];

// Loading resource file: Load a Texture (Assets/Resources/Textures/texture01.png)
// Audio/clip, Text/JSONfile , Text/Textfile, Sprites/mmmm (mmmm.png)
// Unity - Scripting API: Resources.Load

terrainTexture[0] = new SplatPrototype();
terrainTexture[1] = new SplatPrototype();
terrainTexture[2] = new SplatPrototype();
terrainTexture[3] = new SplatPrototype();
terrainTexture[4] = new SplatPrototype();
terrainTexture[5] = new SplatPrototype();

// Load the resources, these are the terrain textures that are supported.
terrainTexture[0].texture = Resources.Load(“Textures/SandAlbedo”);
terrainTexture[1].texture = Resources.Load(“Textures/GrassHillAlbedo”);
terrainTexture[2].texture = Resources.Load(“Textures/GrassRockyAlbedo”);
terrainTexture[3].texture = Resources.Load(“Textures/CliffAlbedoSpecular”);
terrainTexture[4].texture = Resources.Load(“Textures/MudRockyNormals”);
terrainTexture[5].texture = Resources.Load(“Textures/MudRockyAlbedoSpecular”);

// This causes an error in UNITY 2020
_terrainData.splatPrototypes = terrainTexture;
}
}

thank you
Joseph

I haven’t used the new terrain stuff yet, but generally when posting code, please use code tags: Using code tags properly

If you wanna see some more functioning OLD terrain examples (and I believe there is an upgrade path from old to new, if I’m not mistaken), help yourself to anything that might be interesting in my MakeGeo project, which has some terrain stuff including deformation and splatmapping.

MakeGeo is presently hosted at these locations:

https://bitbucket.org/kurtdekker/makegeo