Advertisement
Hazkin

Untitled

Sep 15th, 2021
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  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.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement