Unity Remove Missing Scripts

[Solved] Unity Remove Missing Scripts | Php - Code Explorer | yomemimo.com
Question : unity remove missing scripts

Answered by : enthusiastic-earthworm-bwi8vcx9tndb

using UnityEditor;
using UnityEngine;
namespace FLGCoreEditor.Utilities
{ public class FindMissingScriptsRecursivelyAndRemove : EditorWindow { private static int _goCount; private static int _componentsCount; private static int _missingCount; private static bool _bHaveRun; [MenuItem("FLGCore/Editor/Utility/FindMissingScriptsRecursivelyAndRemove")] public static void ShowWindow() { GetWindow(typeof(FindMissingScriptsRecursivelyAndRemove)); } public void OnGUI() { if (GUILayout.Button("Find Missing Scripts in selected GameObjects")) { FindInSelected(); } if (!_bHaveRun) return; EditorGUILayout.TextField($"{_goCount} GameObjects Selected"); if(_goCount>0) EditorGUILayout.TextField($"{_componentsCount} Components"); if(_goCount>0) EditorGUILayout.TextField($"{_missingCount} Deleted"); } private static void FindInSelected() { var go = Selection.gameObjects; _goCount = 0; _componentsCount = 0; _missingCount = 0; foreach (var g in go) { FindInGo(g); } _bHaveRun = true; Debug.Log($"Searched {_goCount} GameObjects, {_componentsCount} components, found {_missingCount} missing"); AssetDatabase.SaveAssets(); } private static void FindInGo(GameObject g) { _goCount++; var components = g.GetComponents<Component>(); var r = 0; for (var i = 0; i < components.Length; i++) { _componentsCount++; if (components[i] != null) continue; _missingCount++; var s = g.name; var t = g.transform; while (t.parent != null) { s = t.parent.name +"/"+s; t = t.parent; } Debug.Log ($"{s} has a missing script at {i}", g); var serializedObject = new SerializedObject(g); var prop = serializedObject.FindProperty("m_Component"); prop.DeleteArrayElementAtIndex(i-r); r++; serializedObject.ApplyModifiedProperties(); } foreach (Transform childT in g.transform) { FindInGo(childT.gameObject); } } }
}

Source : | Last Update : Mon, 21 Nov 22

Answers related to unity remove missing scripts

Code Explorer Popular Question For Php