- Home /
How to access a texture for reading on the editor?
I am trying to do a simple script that will export all textures from a selected model as PNGs. (Texture2D.EncodeAsPNG())
But I am hitting a brick wall with the following error:
UnityException: Texture 'textureName' is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings.
I've tried to programatically setting it as isReadable = true
string path =
AssetDatabase.GetAssetPath(o.renderer.sharedMaterial.mainTexture);
TextureImporter ti =
(TextureImporter) TextureImporter.GetAtPath(path);
ti.isReadable = true;
I've also tried setting it as readable not programatically, but without any success. Also, setting them as readable would make them be readable in the runtime, which isn't what I want. Is there any way to do that?
Thank you very much!!
Answer by Mike 3 · Dec 25, 2010 at 06:27 AM
After setting isReadable, do this:
AssetDatabase.ImportAsset(path);
That'll reimport the asset in a blocking way, meaning that you can encode to png, and then set back the isReadable setting as it was before changing it
thank you very much, $$anonymous$$ike!! It worked!! And even better, it will work when I reimport it as unreadable!
Thanks!
Your answer
Follow this Question
Related Questions
Editor class "Texture Importer" question (applying settings to multiple texture assets). 2 Answers
EditorWindow loses Texture2D reference on scene change: how to handle? 4 Answers
UnityEditor - Drawing on a Texture 1 Answer
[Solved] How can I change Texture2D format in Editor Script? 1 Answer
Set MinWidth for EditorWindow 1 Answer