I’m having problems after build. In preview everything works fine but after build there are errors.
After build I’m having the exception ‘NullReferenceException: Object reference not set to an instance of an object’ here:
void hideTreeOfObjects(GameObject ob){
for (int i = 0; i < ob.transform.childCount; i++) {
//for some reason child = null in build, but child != null in preview
GameObject child = ob.transform.GetChild(i).gameObject; /*line 229*/
try{
child.GetComponent<MeshRenderer> ().enabled = false;
}catch(MissingComponentException){}
try{
if (child.tag != "lostdetector" && !VRmode){
child.GetComponent<Collider> ().enabled = false;
}
}catch(MissingComponentException){}
try{
child.GetComponent<LineRenderer> ().enabled = false;
}catch(MissingComponentException){}
hideTreeOfObjects (child);
}
}
This function disables some components for every GameObject in a hierarchy tree. It’s called by this functions in the same script (UIManager.cs):
//[...]
public GameObject Indicators;
//[...]
void hideIndicators(){
hideTreeOfObjects (Indicators);
}
public void OnClickRepository(){
setMode (3);
PathItem.hideAllPathPoints ();
hideIndicators ();
selectedObject = null;
selectedObjectToCreate = null;
refreshUI ();
}
void Start () {
OnClickRepository ();
refreshUI ();
loadRepositoryUI ();0
}
This is the GameObject Indicators. It has only the transform component:
The GameObject Indicators is assigned properly in the inspector of the GameObject which uses the UIManager component:
Why is this happening?