Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

UnityWebRequest.downloadProgress skips end

Discussion in 'Connected Games' started by Aeonvirtual, Sep 8, 2018.

  1. Aeonvirtual

    Aeonvirtual

    Joined:
    Oct 14, 2015
    Posts:
    25
    Hi All,

    I'm trying to make a fancy loading wheel for my application and it works but it skips the end because downloadProgress skips its end

    The end of download progress goes something like this:
    ....85%86%87%89% Done!
    or this..
    0% 21% 43% 50% Done!

    I figure it might have something to do with the way I serve up files so here is the PHP code that is serving up these files:
    Code (CSharp):
    1.  
    2. header('Content-Description: Asset Bundle Transfer');
    3. header('Content-Type: application/octet-stream');
    4. header("Content-Disposition: attachment; filename*=UTF-8''".rawurlencode($name));
    5. header('Content-Transfer-Encoding: binary');
    6. header('Expires: 0');
    7. header('Cache-Control: must-revalidate');
    8. header('Pragma: public');
    9. header('Content-Length: ' . filesize($filePath));
    10.    
    11. // echo file_get_contents($filePath);        // tried with this, same issue
    12.                
    13. // read in chunks so we don't get a memory error          
    14. $chunkSize = 1024 * 1024;
    15. $handle = fopen($filePath, 'rb');
    16. while (!feof($handle))
    17. {
    18.       $buffer = fread($handle, $chunkSize);
    19.        echo $buffer;
    20.        ob_flush();
    21.        flush();
    22. }
    23. fclose($handle);
    One thing that is suspicious is that if I use my browser to make this request, the Content-Length header is suspiciously missing, with both the chunked, and the naive approach.

    For completeness sake, here is my unity code:
    Code (CSharp):
    1. uwr.SendRequest();
    2. while(!uwr.isDone) {
    3. Debug.Log(uwr.downloadProgress);
    4. yield return waitFrame;
    5. }
    Has anyone else encountered this problem?
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,142
    Try outputing uwr.bytesDownloaded besides downloadProgress.
    Also, what DownloadHandler are you using?
     
  3. Aeonvirtual

    Aeonvirtual

    Joined:
    Oct 14, 2015
    Posts:
    25
    The code is in a using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(url)){
    block and I don't specify a downloadhandler.

    I checked downloaded bytes and it reports exactly the same number of bytes as the file, however, when it reaches this number, downloadprogress is at 0.88
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,142
    The helper utility you call attaches DownloadHandlerAssetBundle.
    As for progress, this is specific to AssetBundles, the progress attempts to indicate the progress of the whole operation, which is download + AssetBundle load.
     
  5. Aeonvirtual

    Aeonvirtual

    Joined:
    Oct 14, 2015
    Posts:
    25
    so why does it skip the end then? Seems like a bug to me. It would make more sense for the downloadprogress to be 1 when the loop ends.
     
  6. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,142
    That end indicates how much of work is left to load AssetBundle. After you take AssetBundle out from DownloadHandler, progress will be 1. I think this is a bit of legacy from old WWW class.
     
  7. Aeonvirtual

    Aeonvirtual

    Joined:
    Oct 14, 2015
    Posts:
    25
    Well, do you know how I could make a loading bar then that smoothly goes all the way to the end, because I can't use downloadprogress because that smoothly goes to 90%, or 70%, or 50% and then skips to the end.
     
  8. Aeonvirtual

    Aeonvirtual

    Joined:
    Oct 14, 2015
    Posts:
    25
    So, just to make sure, is the current behavior correct? Or should I file a bug report?
     
  9. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,142
    It is considered correct.
     
  10. Aeonvirtual

    Aeonvirtual

    Joined:
    Oct 14, 2015
    Posts:
    25
    Ok, so you can confirm then that there is no way to make a progress bar that smoothly goes to the end? It will always smoothly go to 70 or 80% and then skip? I'm not trying to be an ass, just wondering what I'm doing wrong.
     
  11. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,142
    I don't know whether the actual figure are correct, but UnityWebRequest by design reports progress from AssetBundle system, so it's progress is equal to the progress of underlying AssetBundle load operation.
     
  12. 13Flo

    13Flo

    Joined:
    Jun 9, 2015
    Posts:
    87
    Hey @Aeonvirtual , can I ask you how/where you host your files?

    I'm trying to use AppEngine and PHP but I can not figure out how to get download progress. I just don't get any, like if Content-size was missing from the response.

    Code (CSharp):
    1. using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle("https://myurl/mybundle"))
    2.         {
    3.             yield return uwr.SendWebRequest();
    4.  
    5.             if (uwr.isNetworkError || uwr.isHttpError)
    6.             {
    7.                 Debug.Log(uwr.error);
    8.             }
    9.             else
    10.             {
    11.                 while(!uwr.isDone)
    12.                     Debug.Log(uwr.downloadProgress);
    13.             }
    14. }
    My code yield on return uwr.SendWebRequest() until the file is loaded and uwr.isDone returns true.

    Any help would be much appreciated!