I’ve seen occasional “Combine mesh instance 0 is null” warnings before, but this script is giving tons of them each time it runs.
(…combine mesh instance 1263 is null, combine mesh instance 1266 is null, combine mesh instance 1269 is null, combine mesh instance 1272 is null…)
It’s only one every three, for whatever reason.
I don’t understand what’s wrong here, or how to fix it, and why I’m not getting any NullReferenceException errors if those warnings really mean what they say.
And other than generating over a thousand warnings, the function works just fine- it IS currently combining all the plants into one mesh, and all their shadows into another mesh.
the offending code:
function Flatten () {
var meshFilters = GetComponentsInChildren.<MeshFilter>() as MeshFilter[]; //find all meshes
var shadowMFs : List.<MeshFilter> = new List.<MeshFilter>();
var solidMFs : List.<MeshFilter> = new List.<MeshFilter>();
for (var pmf : MeshFilter in meshFilters) //sort all meshes into shadows and not-shadows
{
if (pmf.gameObject.layer == 27) { shadowMFs.Add (pmf); }
else { solidMFs.Add (pmf); }
}
var combineShadows : CombineInstance[] = new CombineInstance [shadowMFs.Count];
for (var i = 0; i < shadowMFs.Count; i++) //build a CombineInstance for all the shadows
{
combineShadows_.mesh = shadowMFs*.sharedMesh;*_
combineShadows_.transform = shadowMFs*.gameObject.transform.localToWorldMatrix;
shadowMFs.gameObject.SetActive (false);
}
Debug.Log (“ShadowMFs :” +i);
transform.Find(“Shadows”).GetComponent (MeshFilter).mesh = new Mesh ();
transform.Find(“Shadows”).GetComponent (MeshFilter).mesh.CombineMeshes (combineShadows); //combine them
transform.Find(“Shadows”).gameObject.SetActive (true);
var combinePlants : CombineInstance[] = new CombineInstance [solidMFs.Count];
for (var j = 0; j < solidMFs.Count; j++) // build a CombineInstance for all the solid objects
{
combinePlants[j].mesh = solidMFs[j].sharedMesh;
combinePlants[j].transform = solidMFs[j].gameObject.transform.localToWorldMatrix;
solidMFs[j].gameObject.SetActive (false);
}
Debug.Log (“SolidMFs :” +j);
transform.GetComponent (MeshFilter).mesh = new Mesh ();
transform.GetComponent (MeshFilter).mesh.CombineMeshes (combinePlants); // /!\ THE WARNING IS CAUSED HERE /!*
transform.gameObject.SetActive (true);
renderer.sharedMaterial = solidMat;
for (var childT : Transform in myTransform as Transform) // clean up empty prefabs
{
* if (childT.gameObject.name == “Shadows”) {
childT.gameObject.GetComponent.().sharedMaterial = shadowMat;
} else {
Destroy (childT.gameObject, 0.1);
}
}*
yield;
}_