Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

UnityWebRequest.downloadProgress skips end

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

  1. Aeonvirtual

    Aeonvirtual

    Joined:
    Oct 14, 2015
    Posts:
    22
    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:
    1,874
    Try outputing uwr.bytesDownloaded besides downloadProgress.
    Also, what DownloadHandler are you using?
     
  3. Aeonvirtual

    Aeonvirtual

    Joined:
    Oct 14, 2015
    Posts:
    22
    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:
    1,874
    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:
    22
    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:
    1,874
    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:
    22
    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:
    22
    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:
    1,874
    It is considered correct.
     
  10. Aeonvirtual

    Aeonvirtual

    Joined:
    Oct 14, 2015
    Posts:
    22
    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:
    1,874
    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.