- Home /
WWW is twice faster than UnityWebRequest for load streaming asset raw pngs
Hello, I used unity web request to async load raw png textures in streaming path. However, I found out that the lagacy WWW class is actually twice faster than Unity Web Request.
I ran a for loop to load 200 pngs from streaming path. I did a test and it cost 2.8 seconds for WWW, but 5.7 seconds for Unity Web Request.
Code as below, WWW method
public static IEnumerator GetStreamingTexture(string inUrl, Action<Texture2D> onSuccess)
{
WWW localFile = new WWW(inUrl);
yield return localFile;
onSuccess(localFile.texture);
}
Unity Web Request:
public static IEnumerator GetStreamingTexture(string inUrl, Action<Texture2D> onSuccess)
{
using (UnityWebRequest www = UnityWebRequestTexture.GetTexture(inUrl))
{
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
print(www.error);
}
else
{
Texture2D myTexture = DownloadHandlerTexture.GetContent(www);
onSuccess(myTexture);
}
}
}
for loop to call those methods:
foreach (EWPlaceData place in EWGameManager.instance.GetPlacesByCategory(inCategory))
{
// basically retrieve 200 raw png textures one by one.
Texture2D downloadedTexture = null;
string streamingUrl = EWDownloadManager.GetThumbnailImageStreamingPath(place);
yield return EWDownloadManager.GetStreamingTexture(streamingUrl,
(loadedTexture) =>
{
downloadedTexture = loadedTexture;
// do my stuffs here for loaded texture.
}
);
}
Does anyone know why WWW method is faster than UnityWebRequest? The latter should be more efficient as highlighted from Unity.
Is there a better way to bulk load multiple textures in streaming asset?
Your answer
Follow this Question
Related Questions
save cookie after login and use it for login again 0 Answers
Is there a way to load images into a WebGL app? 2 Answers
How to constantly get new JSON information with GET request from a stream? Help!! 0 Answers
Acessing Steaming Assets folder in Android 1 Answer
WWW streaming ogg video problems 1 Answer