Problem with WWW.progress

Hi Guys.

Im working on app wihich is comunicating with server database through php. Problem is when i want to
make progress bar for this communication. From what i know and read all over unity forums and internet… my code is right… from first i thought problem is in content-header which i was missing… but nothing changed when i added it.

Problem is that progress variable is 0 and when its complete its jump to 1. better yet… Debug.Log indicates that progress is nothing… not even 0… so no progress at all… as if unity coudnt get how many bytes was downloaded so far and thus cant make float number like bytesDownloaded/bytesTotal …

So where is problem ? In my server ? or some missing info from header ? or bug in unity ?

here is my C# which makes Loading bar…

using UnityEngine;
using UnityEngine.UI;

public class LoadingBar : MonoBehaviour
{

	public GameObject progressRadial;
    private bool inProgress;
    private float progress;

	[SerializeField]
	private Text progressText;

	[SerializeField]
	private Image progressCircle;

    void Start ()
	{
		progressRadial.SetActive (false);
		progressCircle.fillAmount = 0f;
        InProgress = false;
        Progress = 0f;
        progressText.text = "0%";
    }
	void Update ()
	{
		if (InProgress) {
			progressRadial.SetActive (true);
			progressText.text = (Progress * 100).ToString ("#") + "%";
			progressCircle.fillAmount = Progress;
			Debug.Log ("DOWNLOAD PROGRESS : " + (Progress * 100).ToString("#") + "%");
		} else {
			progressRadial.SetActive (false);
        }
	}

    public bool InProgress
    {
        get
        {
            return inProgress;
        }

        set
        {
            inProgress = value;
        }
    }

    public float Progress
    {
        get
        {
            return progress;
        }

        set
        {
            progress = value;
        }
    }

}

And here is one testing method which handles download from server

public IEnumerator getListUsers(Action<string> result)
    {
        Debug.Log("DatabaseHandler.GETLISTUSERS: START");

        string hash = md5(secretKey);

        WWWForm frm = new WWWForm();
        frm.AddField("list_users","true");
        frm.AddField("hash", hash);

        WWW hs = new WWW("web adress", frm);

        Debug.Log("DatabaseHandler.GETLISTUSERS: DOWNLOADING");
        loadbar.InProgress = true;
        int count = 1;
        while (!hs.isDone)
        {
            loadbar.Progress = hs.progress;

            Debug.Log(count + " - " + hs.bytesDownloaded);
            count++;

        }

        yield return hs;

        loadbar.InProgress = false;
        Debug.Log("DatabaseHandler.GETLISTUSERS: DOWNLOAD FINISHED");

        if (hs.responseHeaders.ContainsKey("CONTENT-LENGTH"))
        {
                Debug.Log(hs.responseHeaders["CONTENT-LENGTH"]);
        }

        if (!string.IsNullOrEmpty(hs.error))
        {
            Debug.Log("DatabaseHandler.GETLISTUSERS: ERROR" + hs.error);
        }
        else
        {
            Debug.Log("HSTEXT: " + hs.text);
            result(hs.text);
        }

        Debug.Log("DatabaseHandler.GETLISTUSERS: STOP");
    }

Sooo… my only solution so far is to make just indicator for internet activity without any loading… but this should work or not ? I tested on android also… no change.

The problem probably lies on the server side. The script that generates the database output probably doesn’t set the “content-length” header, so that the receiving side (Unity in this case) does not know in advance how many bytes it will receive.

Well it makes sense that it’s not showing every step of the progress. In this code

while (!hs.isDone)
         {
             loadbar.Progress = hs.progress;
 
             Debug.Log(count + " - " + hs.bytesDownloaded);
             count++;
 
         }

you’re not yielding or anything, so this runs to its entirety while the Update from LoadingBar doesn’t.

Try yielding at the end of that while, like this

while (!hs.isDone)
         {
             loadbar.Progress = hs.progress;
 
             Debug.Log(count + " - " + hs.bytesDownloaded);
             count++;
             yield return null;
 
         }

Yes, you are right… my bad… this way progress bar doesnt work but method yes. Ofcourse i had it right way but in the end i tried everything even taking yield out of the loop…

normally I have yield return hs; in loop… i tried yield return null; too no change…

Another interesting thing is that when i make contnet lenght long number like 10000000
it shows progress bar 0% as always… but in console my debug method shows DOWNLOAD PROGRESS : %
for +/- 20times… and then it ends download.

debug method is in loadingbar class

Debug.Log ("DOWNLOAD PROGRESS : " + (Progress * 100).ToString("#") + "%");

where progress is practically www.progress variable… and there is nothing not even 0… so its empty ?