Terrain Layers cannot be populated at the same time as the splats
Can you help me with this. After upgrade to 2018.3 I got this error: "Terrain Layers cannot be populated at the same time as the splats". I used my script wich I made a year ago. How can I use this new layers instead of splatPrototypes? Thanks/
Answer by FreebordMAD · Sep 26, 2019 at 10:08 AM
Using TerrainData.splatPrototypes is deprecated, see link below https://docs.unity3d.com/ScriptReference/TerrainData-splatPrototypes.html
Instead use TerrainData.terrainLayers, which provide much more flexibility, normal maps and other shader properties, see link below https://docs.unity3d.com/ScriptReference/TerrainData-terrainLayers.html
Example of Unity version independent code, reduce Unity version if needed as this issue came somewhere in 2018:
#if UNITY_2019_2_OR_NEWER
TerrainLayer[] layersOld = terrain.TerrainData.terrainLayers;
TerrainLayer[] layersNew = new TerrainLayer[layersOld.Length+1];
System.Array.Copy(layersOld, layersNew, layersOld.Length);
layersNew[layersNew.Length-1] = new TerrainLayer();
layersNew[layersNew.Length-1].diffuseTexture = TERRAIN_TEXTURES[textureIndex];
layersNew[layersNew.Length-1].tileSize = TERRAIN_TEXTURE_SIZES[textureIndex];
layersNew[layersNew.Length-1].tileOffset = TERRAIN_TEXTURE_OFFSETS[textureIndex];
terrain.TerrainData.terrainLayers = layersNew;
#else
SplatPrototype[] splatTexturesOld = terrain.TerrainData.splatPrototypes;
SplatPrototype[] splatTexturesNew = new SplatPrototype[splatTexturesOld.Length+1];
System.Array.Copy(splatTexturesOld, splatTexturesNew, splatTexturesOld.Length);
splatTexturesNew[splatTexturesNew.Length-1] = new SplatPrototype();
splatTexturesNew[splatTexturesNew.Length-1].texture = TERRAIN_TEXTURES[textureIndex];
splatTexturesNew[splatTexturesNew.Length-1].tileSize = TERRAIN_TEXTURE_SIZES[textureIndex];
splatTexturesNew[splatTexturesNew.Length-1].tileOffset = TERRAIN_TEXTURE_OFFSETS[textureIndex];
terrain.TerrainData.splatPrototypes = splatTexturesNew;
#endif
Answer by ProudLilac · Feb 11, 2019 at 02:21 PM
I got the same problem. If you have solved it, please tell me how you did.