Unity3d 2018 bundle打包崩溃问题的查找修复
unity2018有很多新特性,尤其引入了嵌套prefab,有点不习惯,但是还是要学习和用,这里整理一下bundle build奔溃的问题;
问题:我在项目中build bundle 莫名其妙unityEditor就闪退了,查找好多资料和网上资料都没有找到问题
script missing就不说了,查找到改了,一样会闪退,所以不是这个问题;
有兴趣你们可以查看这篇文章:
Unity 检查丢失引用的资源 Missing
这篇文章很详细;
下面我们看一个示例:
GameObject是第一个Prefab
箭头GameObject-B是另一个 嵌套的prefab
现在我们删除GameObject-B:
拖进来GameObject:
可以看到GameObject-B依然健在
重点来了我们Open这个prefab GameObject:
看到了没变成了上图:GameObject-B (Missing Prefab),下面还多了一个:Missing Prefab (Dummy)
通过在项目中不断的排除法,只有删除Missing Prefab 就能正常打包了;
现在附上missing prefab查找代码;
直接查找是查不到的因为只有open prefab这个Missing Prefab才能出现,所有必须调用 PrefabUtility.LoadPrefabContents(filePath);打开才能行,下面是代码:
[MenuItem("Tools/Find Build Crash prefabs")]
public static void FindCrashMissingPrefabs() {
string[] allassetpaths = AssetDatabase.GetAllAssetPaths();
EditorUtility.DisplayProgressBar("Bundle Crash Find", "Finding...", 0f);
int len = allassetpaths.Length;
int index = 0;
foreach (var filePath in allassetpaths)
{
EditorUtility.DisplayProgressBar("Bundle Crash Find", filePath, (index + 0f)/(len + 0f));
if (filePath.EndsWith(".prefab"))
{
GameObject fileObj = PrefabUtility.LoadPrefabContents(filePath);
if (fileObj)
{
Component[] cps = fileObj.GetComponentsInChildren<Component>(true);
foreach (var cp in cps)
{
if (cp)
{
PrefabInstanceStatus _type = PrefabUtility.GetPrefabInstanceStatus(cp.gameObject);
if (_type == PrefabInstanceStatus.MissingAsset)
{
//string nodePath = PsdToUguiEx.CopyLuJin(null)+"/"+ fileObj.name;
Debug.LogError("Crash Bundle Missing Prefab:Path=" +filePath +" Name:"+ fileObj.name + " ComponentName:" + cp);
}
}
}
}
PrefabUtility.UnloadPrefabContents(fileObj);
}
index++;
}
EditorUtility.ClearProgressBar();
}
祝好运!
找到后删除Missing Prefab节点,成功解决问题!