- Home /
WWW loading not working on Windows, working on Mac
Hi, I am attempting to load a user selected image file into a Sprite at runtime using the following code
fullFilePath = "file://" + userPath;
fileObject = new WWW(fullFilePath);
// Create new Sprite based on the loaded file
Sprite newSprite = Sprite.Create(fileObject.texture,
new Rect((float)(Screen.width / 2 - (fileObject.texture.width / 2)),
((float)(Screen.height / 2) - (fileObject.texture.height / 2)),
(float)fileObject.texture.width,
(float)fileObject.texture.height),
Vector2.zero);
Even though this works on a Mac, when running the project on Windows8.1 i get the following error: You are trying to load data from a www stream which had the following error when downloading. Couldn't open file /Users/George/Pictures/1376532887242.jpg
Any ideas on what could be going wrong?
Many Thanks
Answer by ajketan · Aug 04, 2014 at 01:32 PM
Try creating the sprite once your WWW operation is complete.... I mean use "www.isDone" or in your case "fileObject.isDone" as a check before creating the sprite.
I am assuming that you are using a Coroutine for this ...if not you must....because WWW is an async operation
Follow the code....
if(fileObject.isDone)
{
// Create new Sprite based on the loaded file
Sprite newSprite = Sprite.Create(fileObject.texture,
new Rect((float)(Screen.width / 2 - (fileObject.texture.width / 2)),
((float)(Screen.height / 2) - (fileObject.texture.height / 2)),
(float)fileObject.texture.width,
(float)fileObject.texture.height),
Vector2.zero);
}
Hope that is helpful
Cheers Ketan
Thanks $$anonymous$$etan! I was missing the .isDone method and your way works great on a mac and even with images off an html address. For some reason if I select any image on my Windows machine it produces an error, starting to think it has something to do with permissions. George
Your answer
Follow this Question
Related Questions
NullReferenceException UnityEngine.MonoBehaviour.StartCoroutine 3 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers