- Home /
Loading a texture from disk fails, but only on iOS.
So I have this very simple method. It loads a texture file from disk, and returns it. Works perfectly in the editor and on Android. However on iOS apparently the file doesn't exist, even though I have verified that it indeed does. The path is built using Application.persistentDataPath, and the file in question is downloaded from a remote server and saved locally, and that all seems to be working just fine.
If I grab the documents folder from the device, the image indeed exists in the correct place, and can be opened with no problems.
Nonetheless, the method keeps returning: File /var/mobile/Containers/Data/Application/{APP GUID}/Documents/itm/27/texture_file.png does not exist
Is there something I don't know about handling reading files on iOS?
static Texture2D LoadTexture(string path)
{
if (!string.IsNullOrEmpty(path))
{
return null;
}
if (File.Exists(path))
{
var tex = new Texture2D(2, 2);
var bytes = File.ReadAllBytes(path);
if (tex.LoadImage(bytes))
{
return tex;
}
else
{
Debug.LogFormat("Texture could not be loaded! {0}", path);
return null;
}
}
else
{
Debug.LogFormat("File {0} does not exist", path);
return null;
}
}
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Combine Array of Sprites to Form One Sprite 0 Answers
Handheld.PlayFullScreenMovie not working with AutoRotation 0 Answers
iOS crash with "Memory pressure" error - too many sprites? 0 Answers