Unity3d 2018 bundle crash 打包崩潰問題的查找修復

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節點,成功解決問題!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章