Need to Set Texture AlphaSource to FromGrayScale in an Editor Script
In my Editor script I need to change a texture's AlphaSource to FromGrayScale and I am struggling. What I have:
string path = string.Format("{0}{1}{2}{3}{4}{5}", _applicationPath, "/Resources/Models/", _importCharacterName, "/Textures/", texture, ".jpg");
TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter;
importer.alphaSource = TextureImporterAlphaSource.FromGrayScale;
I get a null reference for the object. I verified the path to the texture via debug to ensure it was correct as well.
Answer by cansub · Jun 14, 2018 at 03:46 PM
Solved - my path was too prescriptive...
string path = string.Format("{0}{1}{2}{3}{4}","Assets/Resources/Models/", _importCharacterName, "/Textures/", texture, ".jpg");
Your answer
![](https://koobas.hobune.stream/wayback/20220612164750im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is it possible to read an image made up of vertex positions and use those positions 0 Answers
How can I save a texture and edit its importer options with TextureImporter in the same pass? 1 Answer
TextureImporterType.Sprite does not work 0 Answers
How to rename individual sprite slice without creating new fileID in meta file using code? 0 Answers