- Home /
Changing Terrain tint color via script
Hello, I have a Terrain with a few TerrainLayers and I would like to change the tint color of the TerrainLayers via script. The tint color property is only visible through the Terrain inspector and not through the TerrainLayer inspector and likewise, I don't see a colorTint property in the visual studio suggestions under terrainLayer. Interestingly though, changing the color tint changes the color for all terrains that use that TerrainLayer. Does anybody know if it is possible to change the TerrainLayer color tint via script?
If not, the only alternative I see would be to create new textures with the color already baked in and apply those via script using the terrainLayer.diffuseTexture property.
Thanks.
Um... I don't see any tint color in the terrain, only Grass Tint which corresponds to TerrainData.wavingGrassTint.
In the Paint Terrain tab, under Paint Texture, you need to create a terrain layer with a texture then click on that. There is where you see tint color.
I still don't see it, but I assume you're using a custom terrain material (or a different type or project/other Unity version). You probably can change the color by adjusting that material.
Answer by Edwige · Feb 16, 2021 at 03:25 PM
The documentation and the variables names are not clear at all here, but I found the solution to change the color tint of a terrain layer diffuse:
terrain.terrainData.terrainLayers[layerSlot].diffuseRemapMax = color;
terrain is the Terrain to edit, layerSlot is the number of your layer in the paint texture list on the terrain, it is an int color is a Color, it should be the tint color you want.
Hope this helps :)