load splatalpha in script

Hey guys,

if I create a terrain and texture it somehow, it will create an alphamap called Splatalpha 0 as Child of the terrainData asset, but I cannot find a way to access this alphamap from inside a script, does anyone know how to do this?

Cheers

OK, a created terrain is usually Terrain.activeTerrain:

You get the terrainData…

To access the splat materials you use…

You can use/modify the old ones and create new ones. To do this you may need to create a new SplatPrototype[ ]

Fill them with textures and tileSize and Offset if needed.

Make sure to write it back to the SplatPrototypes variable.

Next Access the alphaMaps by GetAlphaMaps

This will be an array of floats [,] ([x,y,SplatType], SplatType may not exceed SplatPrototypes.Length-1)

Change the floats as needed. Remember that 1.0 of one SplatType and 1.0 of another is 0.5 of both, it does not overwrite as you think.

Write them back to the alpha maps by SetAlphaMaps…

Then write the whole terrainData back to the terrain and don’t forget the terrainCollider and flush the terrain…