I'm using DownloadHandlerTexture.GetContent to get my texture:
www = UnityWebRequest.GetTexture("http://www.example.com/loadTex/?tag=" + tag);
www.SetRequestHeader("Accept", "image/*");
async = www.Send();
while (!async.isDone)
yield return null;
if (www.isError) {
Debug.Log(www.error);
} else {
yield return null;
tex = DownloadHandlerTexture.GetContent(www);
}
After loading I would like to cache it to a file so I do:
byte[] pic = tex.EncodeToPNG();
File.WriteAllBytes(Application.persistentDataPath + "/art/" + tag + ".png", pic);
At this point I get the exception:
UnityException: Texture '' is not readable, the texture memory can not be accessed from
scripts. You can make the texture readable in the Texture Import Settings.
I'm thinking that I need to make it readable somehow. I googled it, but the only answers I get is to how to make it readable through the editor.