- Home /
WWW and threads
I have a bunch of textures I want to load with WWW (if possible) but maybe waiting for them with yield is not efficient. Can I put each WWW request in a new thread somehow so one texture doesn't necessarily block others? What's the best way to do this?
Answer by TomNCatz · Sep 29, 2011 at 04:18 PM
Any function name that you come up with (something other then Update, FixedUpdate, Start, etc.) basically takes place in it's own thread. So if you create a function like RetrieveTexture and call it for each texture in turn, the yields will be handled independent of each other. That way if the first texture you call for takes the longest to download, then it will simply be the last to finish.
public var textures : Texture[];
RetrieveTexture( url : String, slot : int ) {
// call for texture download based on URL and yield till done
textures[slot] = //retrieved texture
}
You could also create a separate function for each texture you're loading if there are more independent requirements for each, but that gets to be a lot fo function code quickly.