- Home /
UnityWebRequest post freezes in WebGL build
I have some code that loads data from a server. It works fine running in the Unity editor. But, it freezes when I do a WebGL build. Looking at the traffic in the Network tab of my browsers debug console, I can see that the server returns the correct data in a timely manner. UnityWebRequest just doesn't do anything with it. Here is my code.
Debug.Log("sending request to " + strURL);
UnityWebRequest unityWebRequest = UnityWebRequest.Post(strURL, lstFormData);
unityWebRequest.timeout = 60;
Debug.Log("Befor Sending");
//yield return during request for WebGL
UnityWebRequestAsyncOperation async = unityWebRequest.SendWebRequest();
Debug.Log("Waiting for request to finish");
while (!async.isDone)
{
Debug.Log("Waiting..."); //this happens once
yield return 0;
}
Debug.Log("After Sending"); //this never happens on a WebGL build
Is there something I'm missing? BTW, I am running Unity 2018.4.18f1.
Thanks in advance,
Mike
Answer by 3dGeek · Jun 04, 2020 at 08:07 PM
I figured out what was causing my issue. After the call to the coroutine above, I was calling System.Threading.Thread.Sleep(1000) to solve a timing issue with the desktop version of my app. The call to Sleep() was locking up WebGL completely. Since the call to UnityWebRequest.SendWebRequest() happened asynchronously, both functions were being executed at the same time. I incorrectly assumed SendWebRequest() was causing the issue.
Your answer
Follow this Question
Related Questions
Can I run unity with this system? 3 Answers
Why Is This Inactive Script Is Still Affecting My Game? 0 Answers
How can I get a variable from another player? 0 Answers
How To Sync Scale in UNET 2 Answers