multiple WWWs

Can there be more than one WWW going at once? for example, could I have two separate assets being downloaded at the same time? I am getting weird behavior with WWWs when there is more than one at a time.

Hi Yoggy,

I’m doing this in a current project. I wrote a little wrapper code to handle the WWW operation and attached that to an empty gameObject. Then in my main code I instantiate a bunch of those and store them in an array. When I need to make a www call I check the status of the www instances to find one that is idle and then call a function on it to start the www op.

Gee… that’s clear :wink:

It’s a bit more effort than I’d like but it is working well. I keep it to 4 www operations max since I don’t want to saturate the net connection.

–Roy


This is the code that spawns the www instances:

var wwwLoader: Component;
 
//
 
private var wwwLoader_array : Array; //instances of www class
 
function Start () {
 
	wwwLoader_array = new Array();
	//
 
	//
	for (i= 0; i < 4; i++){
		loader	=  Instantiate(wwwLoader);
		wwwLoader_array.push(loader);
		script = loader.GetComponent("rpWWWclass");
 		script.SetUp(gameObject, "webOpComplete", i);
 	}
 	//
 
}
 

//function to find an idle loader
 
 function GetLoader(){
 	
 	for (i = 0; i < wwwLoader_array.length; i++){
   		loader = wwwLoader_array[i];
  	 	script = loader.GetComponent("rpWWWclass");
	  	 	if (script.GetStatus() == false){
	  	 		return script;
	  	 	}
   		}
	return false;
 }

www wrapper code

// rpWWWclass
// this is a wrapper for the WWW class
// it retrieves an image, stores it in a texture
// and holds it until called

private var callbackObject: GameObject;
private var callbackFunction: String;
private var wwwID: Number;
private var www;
private var WWWinProgress = false;
private var tempTexture;
private var wwwURL;
private var arrayIndex;
//
 
function SetUp(callbackObj, callback, id){
	
	callbackObject = callbackObj;
	callbackFunction = callback;
	wwwID = id;
	myStatus = -1;
}


function StartLoad(url: String, aIndex: Number){
	//
 
	wwwURL = url;
	arrayIndex = aIndex;
	www = WWW(wwwURL);
  	WWWinProgress = true;
 	yield www;
	//
	WWWinProgress = false;
	//
	if ([url]www.error[/url] == null) {
//	 	tempTexture = new Texture2D(128, 256);
		tempTexture = new Texture2D(64, 128);
	 	www.LoadImageIntoTexture(tempTexture);
	 	callbackObject.SendMessage(callbackFunction, wwwID);
	 	
	}else{
		print([url]www.error[/url]);
	 }
}

function GetStatus(){
	return WWWinProgress;
}
//
 function GetArrayIndex(){
	return arrayIndex;
}
//
function GetWWWTexture(){
//
	if (WWWinProgress){
		return false;
	}else{
 		return tempTexture;
	}
}
 
function OnApplicationQuit(){
	www = null;
	
}