Hazkin

Untitled

Sep 15th, 2021
605
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [MenuItem("Tools/Find and Remove missing scripts In Selection")]
  2.     public static void RemoveMissingScripts()
  3.     {
  4.         foreach (var go in Selection.gameObjects)
  5.         {
  6.             var amount = RemoveMissingScripts(go);
  7.             if (amount > 0)
  8.             {
  9.                 Debug.LogFormat($"Removed {amount} missing script(s) in {go.name}");
  10.             }
  11.         }
  12.     }
  13.  
  14.     private static int RemoveMissingScripts(GameObject go)
  15.     {
  16.         int amount = GameObjectUtility.RemoveMonoBehavioursWithMissingScript(go);
  17.         for (int i = 0; i < go.transform.childCount; i++)
  18.         {
  19.             var child = go.transform.GetChild(i).gameObject;
  20.             amount += RemoveMissingScripts(child);
  21.         }
  22.         return amount;
  23.     }
RAW Paste Data