Question by
dlegare_scientific · Sep 30, 2016 at 02:57 PM ·
networkingapiwebrequest
UnityWebRequest only does one request at a time
I'm converting some code that was using WWW
to use UnityWebRequest
. The code is very simple, just download a png and convert the loaded texture to a sprite. When using WWW
all requests seem to run at once and complete at about the same time. When using UnityWebRequest
I can clearly see one image pop in at a time, indicating that only one request is being done at once. I've tested this in the Editor on OS X and on Android, the result is the same on both.
Code with WWW
:
var request = new WWW(url);
yield return request;
if (request.error != null)
{
HandleError(request.error);
}
else
{
var texture = request.texture;
MakeSpriteFromTexture(texture);
}
Code with UnityWebRequest
:
var request = UnityWebRequest.GetTexture(url);
yield return request.Send();
if (request.isError)
{
HandleError(request.error);
}
else
{
var texture = (Texture2D)((DownloadHandlerTexture)request.downloadHandler).texture;
MakeSpriteFromTexture(texture);
}
The two are almost identical, yet the WWW
version performs substantially better. Is there anything I'm doing wrong with UnityWebRequest
that would cause requests to only run one at a time?
Thanks!
Comment