- Home /
Load local file with WWW
Hello,
I try to load a local file with WWW class. Everything works fine, however isDone function return too early. Width the following code:
var path = paths[0];
WWW w = new WWW("file://" + path);
Debug.Log("1: " + Time.realtimeSinceStartup);
while (!w.isDone)
{
Debug.Log("not done");
}
Debug.Log("2: " + Time.realtimeSinceStartup);
images.Add(w.texture);
Debug.Log("3: " + Time.realtimeSinceStartup);
I've got:
1: 0.02761436
2: 0.03673011
3: 0.3329855
There's something wrong here no ?
Regards
EDIT : I tryed with a distant file, and everything works correctly.
Local file access is generally pretty quick. Are you actually encountering a problem, or just expecting one? I'm a little confused. :|
Debug.Log calls are expensive on performance.
Generally speaking - Don't do while (!w.isDone) {} calls without yield or yield with WaitForSeconds(). This is very bad program$$anonymous$$g since it freezes the application/game until a process is done, something you should never do (the term is called "Busy Waiting") - you should always enable your program to continue its main process without doing freezes.
Finally, I have found the problem : there is a delay during the loading of the texture into my Texture2D variable. I try to use LoadImageIntoTexture, but I have the same problem.
I think it is during parsing of received bytes. I can't reduce image size, but I would like to know if there is a way to thread this parsing.
Regards
Answer by GuyTidhar · Apr 14, 2012 at 08:34 AM
I'd try removing the Debug.Log("not done"); within the while loop and then test for times.
Your answer
![](https://koobas.hobune.stream/wayback/20220613070301im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
A node in a childnode? 1 Answer
Screenshot multiple 1 Answer
C# how to save values to a File and Load Values from a File 2 Answers