- Home /
Why WWW class is not working with WebGL
Hello,
I'm having some trouble with the WWW class:
WWW test = new WWW("http://localhost:8888/StreamingAssets/Scenario/ScenarioTest.snr");
while (!test.isDone)
Debug.Log(test.bytesDownloaded);
scenario.LoadFromString(test.text);
When I run this part of code in the Editor, it perfectly works, but in the WebGL exports, test.bytesDownloaded doesn't increase and test.isDone is never true.
In the .htaccess file I've got this:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteRule (.*)Release(.*)\.js $1Compressed$2\.jsgz [L]
RewriteRule (.*)Release(.*)\.data $1Compressed$2\.datagz [L]
RewriteRule (.*)Release(.*)\.mem $1Compressed$2\.memgz [L]
RewriteRule (.*)Release(.*)\.unity3d $1Compressed$2\.unity3dgz [L]
AddEncoding gzip .jsgz
AddEncoding gzip .datagz
AddEncoding gzip .memgz
AddEncoding gzip .unity3dgz
Header set Access-Control-Allow-Credentials "true"
Header set Access-Control-Allow-Headers "Accept, X-Access-Token, X-Application-Name, X-Request-Sent-Time"
Header set Access-Control-Allow-Methods "GET, POST, OPTIONS"
Header set Access-Control-Allow-Origin "*"
I'm not sure whether it's really the issue, but I think the problem lies in while (!test.isDone)
. WebGL is currently not multi-threaded. If (this is my hypothesis) WWW class is actually downloading the data in separate thread in Editor, you can wait with while (!test.isDone)
and then get the result in the Editor or Standalone. In that case, however, implementation of WWW class in WebGL must be different - the downloading must be done in main thread - that means that Unity engine waits until you finish your update and then the downloading is done/continued. But with while (!test.isDone)
you never finish your update, so download method is never called so the downloading never finish, too. That's why yield return www;
works. I guess.
Answer by ZeoWorks · Aug 22, 2015 at 11:40 PM
It seems everyone is having IEnumerator issues in webGL, particularly with firefox. Unfortunately there currently is no known fix.
Ok, it seems it's working with a coroutine which takes the WWW object as parameter:
private IEnumerator $$anonymous$$yCoroutine(WWW www)
{
yield return www;
if (null != www.error)
Debug.Log("WWW Error: " + www.error);
}
Thanks anyway ^^
Your answer
Follow this Question
Related Questions
File Paths to load files with WWW for WebGL 0 Answers
Is there a way to load resources with unkown case (.png/.PNG) using www objects? 1 Answer
How can I get a string to work as the key to a dictionary filled with the text of a www object? 0 Answers
How can I access an external folder in the WebGL build of my app? 1 Answer
How to stream a image or text in webGL? 0 Answers