- Home /
Works in player but NullReferenceException in build.
I'm trying to "highlight" all parts of a model with a certain name. It works perfectly in player but in standalone build I get a NullReferenceException. Object reference not set to an instance of object. Dont understand why it would work in player but not the build. Any ideas? Thanks!
GameObject[] partsList = GameObject.FindGameObjectsWithTag("Part");
foreach(GameObject part in partsList){
if(part.name.Equals(guid)){
part.transform.renderer.material.SetColor("_Color", Color.blue);
}
}
If no game objects have the "Part" tag then partsList will be null and cause the exception when you try to iterate in the foreach loop. Is it possible you're missing a scene in your build settings?
No, the scenes are included. I tried building with just this scene and receive the same problem. The only other scene is just a simple button pointing to this scene anyway.
Answer by rustymonkey · May 21, 2013 at 03:02 PM
I figured it out. I was using a try/catch block for MissingComponentException. I switched to a simple null test of the specific component and it worked. Still dont know why it was caught in player but not in build though.