NullReferenceException: Object reference not set to an instance of an object
UnityEngine.InternalStaticBatchingUtility.CombineGameObjects (UnityEngine.GameObject[] gos, UnityEngine.GameObject staticBatchRoot, System.Boolean isEditorPostprocessScene, UnityEngine.InternalStaticBatchingUtility+StaticBatcherGOSorter sorter) (at 、、
unity运行场景会输出如上log,经查发现该场景中勾选了静态合批的模型有mesh丢失
解决方案:将静态合批取消勾选或者将丢失的mesh解决之后能清掉上述报错
下面是筛出mesh丢失的代码
[MenuItem("检测mesh状态")]
public static void CheckMesh()
{
GameObject obj = Selection.activeGameObject;
if (obj == null) return;
MeshFilter[] filter = obj.GetComponentsInChildren<MeshFilter>(true);
foreach(var item in filter)
{
if(item.sharedMesh == null)
{
Debug.LogError("该meshfilter的mesh为空 " + item);
}
}
}