Texture loading via www.texture not loading!

Hi there,

i tried to load a image via WWW. therefor i created a IEnumerator and started loading with WWW(url).

to show loading progress, i created a progressbar with NGUI, and set a while loop in the ienum. this includes the setting of the progressbar to www.progress, and a yield that waits for the end of the frame.

problem… the www.progress always seems to be 0.0…
so the image isn’t loading :confused:
It´s working for my Audio Listener…

any ideas what can cause this problem?

The Code:

	private WWW www;

[...]

	void OnClick() {
		Debug.Log("Button geklickt!");
		//LADE AUDIOPLAYER
		if(Buttonsprite.spriteName == "Image_Audiofile"){
			Debug.Log("Button ist Audiobutton!");
			StartCoroutine(GetAudiofile());
		}
		else if(Buttonsprite.spriteName == "Image_Imagefile"){
			Debug.Log("Button ist Imagebutton!");
			StartCoroutine(GetImagefile());
		}
	}

[...]

	private string urlstring, cutstring;
	private string[] urlarray;
	IEnumerator GetImagefile(){
		Viewer_Image.SetActive(true);
		Viewer_Main.SetActive(false);
		urlstring = ContentHolder.contents[(int)Ownfields.Arrayfield.x, (int)Ownfields.Arrayfield.y].cont_linkurl;
		www = new WWW(urlstring);
		if(www.error != null){
			Debug.Log("Image WWW ERROR: " + www.error);
		}
		while(www.progress < 1){
			Viewer_Image.transform.Find("StreamingBar").GetComponent<UISlider>().value = www.progress;
			Viewer_Image.transform.Find("Ladestand").GetComponent<UILabel>().text = "Ladestand: " + ((int)(www.progress * 100.0f)).ToString() + "%";
			Debug.Log(www.progress);
			yield return new WaitForEndOfFrame();
		}
		Viewer_Image.transform.Find("StreamingBar").GetComponent<UISlider>().value = 1.0f;
		Viewer_Image.transform.Find("Ladestand").GetComponent<UILabel>().text = "Ladestand: 100%";
		ImagePlane.renderer.material.mainTexture = new Texture2D(www.texture.width,www.texture.height);
		www.LoadImageIntoTexture((Texture2D)ImagePlane.renderer.material.mainTexture);
		ImagePlane.transform.localScale = new Vector3(www.texture.width, www.texture.height, 1);
		ImagePlane.SetActive(true);

	}

I had a similar problem and just solved it.

The trick is to save your textures as PNG before you download them using WWW. Jpg doesn’t download through iOS for some reason.

You should store the WWW var as a global var and update the progress bar on the Update() function. Something like the following:

private WWW www;
private int progress;

public string host;
public string uriVersion;
	
IEnumerator GetWWW () {
	using(www = new WWW("http://" + host + "" + uriVersion)){
			
		yield return www;
			
		if (www.error != null){
			Debug.Log("WWW download had an error:" + www.error);
		}
		else{
			//Do whatever you want with the www var
		}
	}
}

// Use this for initialization
void Start () {
	StartCoroutine(GetWWW());
}
	
void Update () {
	//Store the progress as an integer value
	progress = Mathf.RoundToInt(www.progress * 100f);
}