x


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!!

more ▼

asked Dec 24 '10 at 08:17 PM

Waneck gravatar image

Waneck
61 5 5 10

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Dec 25 '10 at 06:27 AM

Mike 3 gravatar image

Mike 3
30.5k 10 65 253

thank you very much, Mike!! It worked!! And even better, it will work when I reimport it as unreadable!

Thanks!

Dec 25 '10 at 06:10 PM Waneck
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1675
x355
x349
x72

asked: Dec 24 '10 at 08:17 PM

Seen: 3662 times

Last Updated: Dec 07 '12 at 02:38 PM