Texture Atlas saving issue caused by IsReadable.

Hello all,
So here is the issue, I have created a texture atlas tool, giving the user the ability to change the necessary features (i.e. compression, size, etc)…pick the save location and click create…boom. Sounds easy…right…wrong! Upon attempting to save the texture atlas to and external or local (project folder) location. I get an error stating that isReadable is not set and the setPixels function is failing. I have checked and recheck that I am setting the textures in the folder I intend to use to read/write enabled = true.

Thanks for the help everyone…Take care and happy coding! Any thoughts, suggestion or comments are welcome,
Bryan M

It’s not to do with the file permissions, it’s a flag you set on the texture in the inspector.

Yes, I understand there is a Unity flag that must be set to true, in order to write to a read/file. However, the goal of this tool is simply to read external folders containing textures. Create the atlas, and then save it off to a local root or an external location of your choosing. I apologize; I should have made it clearer that I have tried all that I can to negate the fact that Unity is limiting the ability to do so by not allowing the read/write flag to be set from within the script…fail.

That said, I could still have the user add the textures to their project, set the necessary flags, and the pull from that folder…but honestly it losses some of its panache if that is the case.

Bmackenzie

Unity allows the Read/Write flag to be disabled via script, but not enabled.

Easiest way to ignore unity’s settings on Readonly, is to make a new Texture2D() at editor time and load the PNG in manually using the filestream class and this function:
http://unity3d.com/support/documentation/ScriptReference/Texture2D.LoadImage.html

Then when saving instead of using the Unity asset creation functions, and having to set the pixels of an existing asset, which could be readable. Call SetPixels on your Texture2D object so you have control on it’s readability (and not have the import settings change it on you). Then save it using FileStream and EncodeToPNG, allowing Unity’s AssetDatabase to catch it when you are done editting it.

Great, I will give it a go. Thanks for the input

Bmackenzie