- Home /
Get List of Textures (or their names) used on Terrain?
I have a very similar question to the one that was asked over here: http://answers.unity3d.com/questions/220536/get-slope-and-colortexture-at-point-on-terrain.html
My issue with the answer that was provided is it makes the assumption that my "Rock" layer will be in a fixed layer of the alphamap. This isn't my case. I may have levels with 0, 1, or many "Rock" layers. I don't want to have to constantly keep track of which textures are being used on each level. I'd like to write a simple editor script that keeps track of this for me.
Every time I save the file, I want my script to just get each of my terrains, check the textures used, and store in an array which alphamap layers are "Rock" or not based on the name of the texture.
So my question is - how do I programmatically get the names of the textures used on a given piece of terrain? This is happening in an Editor Script, if that helps. I figure it must be possible, because the Unity Editor keeps track of this (or am I mistaken in thinking that all the pieces of the Unity Editor were built using these same classes that we have access to?)
Answer by ArtOfWarfare · Dec 19, 2015 at 03:55 PM
I have found it. The path to get from a Terrain
to the Texture
s used on it is as follows:
Terrain.terrainData
is aTerrainData
TerrainData.splatPrototypes
is aSplatPrototype[]
SplatPrototype.texture
is aTexture2D
And if you'd like the file name, they have a
name
property, or you can useToString()
on them.
This is Obsolete in Unity 2021.2. You should now use terrainLayers instead.
Your answer
![](https://koobas.hobune.stream/wayback/20220612053050im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
OnSceneGUI render projection onto object surface 1 Answer
How do you put color or textures on a terrain? 0 Answers
Where is the "Add Terrain Texture" Button? 0 Answers
Terrain look 1 Answer
Terrain Issue [Video] 1 Answer