-
-
Save XeniaPhe/264d6fd553443fb7a9e1944018338383 to your computer and use it in GitHub Desktop.
Unity Editor Script to help cleaning up missing script references on gameobjects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
public class CleanupMissingScriptsHelper | |
{ | |
[MenuItem("Edit/Cleanup Missing Scripts")] | |
static void CleanupMissingScripts() | |
{ | |
foreach (var go in Selection.gameObjects) | |
{ | |
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(go); | |
} | |
} | |
[MenuItem("Edit/Recursive Cleanup Missing Scripts")] | |
static void RecursiveCleanupMissingScripts() | |
{ | |
Transform transform = Selection.gameObjects[0].transform; | |
foreach (Transform t in transform) | |
{ | |
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(t.gameObject); | |
} | |
} | |
[MenuItem("Edit/Destroy Worlds")] | |
static void ThanosesGauntlet() | |
{ | |
//This goes through the entire hierarchy and removes the missing scripts | |
var everything = GameObject.FindObjectsOfType<GameObject>(); | |
foreach (var go in everything) | |
{ | |
if(go.activeInHierarchy) | |
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(go); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment