IEnumerator skips remaining function after yield
Hi, excuse me for my english. I try to create a webgl with many Materials in it, so i need to download all the textures from the server. Now I have a problem with IEnumerator, as soon the first yield is in the Line of script, IEnumerator skips the whole remaining function. (the least function is, how i fixed it, but i know that's bad Fix) Can someone Help me please to Fix it?
bool MaterialCreated = false;
Material[] Material;
//Material
public Material[] getMaterial()
{
if(!MaterialCreated)
{
MaterialCreated = true;
Material = new Material[1];
Material[0] = Instantiate(Resources.Load("Material/Standard") as Material);
StartCoroutine_Auto(downloadTex(TexturLink));
}
return Material;
}
//CreateMaterial if chosen
private IEnumerator downloadTex(string urlstring)
{
WWW www = new WWW(urlstring);
yield return www;
if (string.IsNullOrEmpty(www.error))
{
Debug.Log("FAIL: " + urlstring);
}
else
{
Material[0].mainTexture = new Texture2D(1024, 1024, TextureFormat.RGB24, false, true);
www.LoadImageIntoTexture((Texture2D)Material[0].mainTexture);
Debug.Log("OK");
}
}
// It works like this, so I know that URL is working so far
private IEnumerator downloadTex(string urlstring)
{
WWW www = new WWW(urlstring);
while (www.progress < 1)
Debug.Log(www.progress);
Material[0].mainTexture = new Texture2D(1024, 1024, TextureFormat.RGB24, false, true);
www.LoadImageIntoTexture((Texture2D)Material[0].mainTexture);
Debug.Log("OK");
yield return www;
}
Comment
Best Answer
Answer by rockalexw · Dec 11, 2015 at 08:48 AM
Found the solution the Obj was active as the Coroutine starts, but with the first yield the Obj was deactivated.
for someone with the same problem, set Scale on Vector.zero, ins$$anonymous$$d of deactivate