- Home /
How to get TextureImporterType from script?
If you create a material and then try to drop a texture that is not a normal map into the material's normal map, you get a warning with a prompt asking if you want to fix your normal map up.
In my own custom editor, I'd like to also validate that a texture is marked as a normal map. It appears that this is defined by the UnityEditor.TextureImporter.
However, I cannot figure out how to get a UnityEditor.TextureImporter from a Texture2D object.
From a script, how can I get the TextureImporterType that was used to import the Texture2D object I have?
Answer by DougRichardson · Oct 29, 2017 at 09:20 PM
// May return null. For example, if the the texture has no backing asset as in the case
// of Texture2D.whiteTexture.
private static TextureImporter ImporterForTexture(Texture texture)
{
var path = AssetDatabase.GetAssetPath(texture);
return (TextureImporter)AssetImporter.GetAtPath(path);
}
Thanks to @Peter77 who helped me with this question in the forums.
Your answer
Follow this Question
Related Questions
List of supported texture formats 1 Answer
Texture2DArray Size Problem 0 Answers
Add existing asset to asset or save PNG into existing asset 2 Answers
Create / Modify Texture2D to Read/Write Enabled at Runtime 3 Answers
Stop compressing image on Android 0 Answers