How can I create or edit a texture, at runtime, with its read/write property enabled? The TextureFormat doesn’t seem to help, and I can’t find out how to make it work.
Note: TextureImporter and AssetDatabase don’t work. They require the UnityEditor namespace, and that doesn’t work in an exported build (I’m making this for iOS).
In the editor, you can just set a texture’s type to Advanced and set its Read/Write Enabled property to true, but of course I don’t have access to the editor at runtime.
“Readonly” only applies to assets that you import at edittime. So if you imported a texture at edittime and you didn’t make it readable, you can’t read it at runtime and you can’t make it readable. So if you need textures which you imported in the editor readable at runtime you have to mark it as readable inside the editor.
Textures created at runtime are always readable unless you pass “true” as second parameter to Apply in which case you made the texture none-readable forever just like an asset that never was.
If you load images at runtime from external sources they also are readable by default
I had a similar issue, and found out why created then saved Texture2D’s weren’t readable after the fact. It’s because once you save it, it saves the texture as “Default”, which default has Read/Write disabled. Edited: I have fixed my original code, it now works!
Edited: NullReferenceException was fixed because I had to call “SaveAssets()” then add in “Refresh()”, and now it works within one call during one runtime!
this code saved my ASS :) well done!
– shacharozMy texture is blank when I use this method. Do you how to fix that?
– rmib200