- Home /
NullReferenceException in nested Coroutine
Hi everyone,
I am trying to load and OBJ 3D model at runtime, using the following code, but I get a NullReferenceException
when calling the SetGeometryData
nested coroutine.
NullReferenceException
at UnityEngine.MonoBehaviour.StartCoroutine (IEnumerator routine) [0x00000] in <filename unknown>:0
at OBJ+<Load>c__Iterator9.MoveNext () [0x00000] in <filename unknown>:0
This is my code:
public IEnumerator Load(string path) {
basepath = (path.IndexOf("/") == -1) ? "" : path.Substring(0, path.LastIndexOf("/") + 1);
WWW loader = new WWW(path);
yield return loader;
yield return StartCoroutine(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();
}
And I am calling this method like this:
public void StartLoading() {
obj = new OBJ("new object");
StartCoroutine(obj.Load(path));
obj.OBJFinishedLoading += new OBJFinishedLoadingEventHandler(OBJLoaded);
}
I tried changing it for StartCoroutine("SetGeometryData",loader.text)
but I got the same result.
Does anybody see anything wrong with it? Any tips, directions, advice?
Thanks!
Comment