- Home /
Download .obj withouth blocking
Hi there,
I am trying to download an .obj file using this code *http://www.everyday3d.com/unity3d/obj/obj.1.2.unitypackage* and it is blocking my game. This is the actual function that blocks the execution.
public IEnumerator Load(string path) {
basepath = (path.IndexOf("/") == -1) ? "" : path.Substring(0, path.LastIndexOf("/") + 1);
WWW loader = new WWW(path);
yield return loader;
SetGeometryData(loader.text);
if(hasMaterials) {
loader = new WWW(basepath + mtllib);
yield return loader;
SetMaterialData(loader.text);
foreach(MaterialData m in materialData) {
if(m.diffuseTexPath != null) {
WWW texloader = new WWW(basepath + m.diffuseTexPath);
yield return texloader;
m.diffuseTex = texloader.texture;
}
}
}
Build();
}
I call that function like this:
void Start () {
obj = new OBJ("monkey");
StartCoroutine(obj.Load(path));
}
And once the code gets to the first yield return
it blocks until everything gets downloaded and processed. I would like to get some advice on how to structure the code so I can avoid that blocking. I have been reading about StarCoroutine
functions as well as yield return
statements and there must be something obvious I am missing.
Thanks in advance
What is actually blocking is the processing of the .obj because it's executed in the same thread than the UI, I'm gonna try to execute it in a background thread so it doesn't interfere with the UI thread.
Your answer
Follow this Question
Related Questions
Unity GameObject Download at runtime 1 Answer
Export objects to a .3DS file at runtime 1 Answer
Download FBX or OBJ at runtime 0 Answers
Asset Bundles download at runtime 1 Answer