- Home /
Adding data to a set of transforms
Hello,
I have a blank gameobject that contains 70 some odd prefabs (generated at run-time). I want to be able to loop through the prefabs and add a WWW object which will be setting its texture as soon as the download completes, but I need to track which prefabs have have WWW objects that aren't isDone, so that I could dispose of the WWW object that is associated with that particular prefab. Here is an example of what I have/need (simplified):
for(var child : Transform in transform){
var txt = new Texture2D(tileSize, tileSize, TextureFormat.DXT1, false);
var www = new WWW("urlgoeshere");
yield www;
www.LoadImageIntoTexture(txt);
child.guiTexture.texture = txt;
child.newpropertynamehere = www; // THIS IS WHAT I NEED
}
So that later I can do:
for(var child : Transform in transform){
if(!child.newpropertynamehere.isDone) child.newpropertynamehere.Dispose();
}
Any help would be greatly appreciated!
Jake
Answer by FishBone · Mar 08, 2012 at 04:48 PM
Let every GameObject have a script that loads the textures and keeps the variables for isDone.
var children : WWWLoader[] = GetComponentsInChildren<WWWLoader>();
for (child : WWWLoader in children)
{
child.Load("urlgoeshere");
}
so later you can do:
for (child : WWWLoader in children)
{
if(!child.isDone) child.Dispose();
}
the WWWLoader-class would look something like
var isDone : boolean;
function Load (url : string) {
var txt = new Texture2D(tileSize, tileSize, TextureFormat.DXT1, false);
var www = new WWW(url);
yield www;
www.LoadImageIntoTexture(txt);
guiTexture.texture = txt;
isDone = true;
}
Thanks for your help on this, I am new to unity and game development so I have to think a bit differently.
I figured it would involve applying a class to the tiles, should I drop this WWWLoader script on the guitexture that is inside the prefab? Or the prefab itself?
Also, does the child.Dispose(); dispose of the WWW object or does it dispose of the whole prefab?
Your answer
![](https://koobas.hobune.stream/wayback/20220613064856im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to center prefabs' children to (0, 0, 0) without changing their position relative to each other 1 Answer
Loading a large xml file (~200 multi-level nodes) into Unity 1 Answer
How to assign Transform to prefab ? 2 Answers
downloading data in background without halting application 1 Answer
WWW and php issues 1 Answer