Last active
July 3, 2024 21:34
-
-
Save EricHu33/1020f1b36c0fcb646fb5d8931c31dd08 to your computer and use it in GitHub Desktop.
Clean all missing scripts in Unity Gameobject, attached this script into the root of the gameobject. right click and call "RemoveMissingScript"
This file contains 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
[ExecuteInEditMode] | |
public class YourComponent : MonoBehaviour | |
{ | |
[ContextMenu("remove missing script")] | |
public void RemoveMissingScript() | |
{ | |
var transforms = GetComponentsInChildren<Transform>(true); | |
foreach (var childTransform in transforms) | |
{ | |
var components = childTransform.GetComponents<Component>(); | |
var hasMissingScript = false; | |
for (int i = 0; i < components.Length; i++) | |
{ | |
if (components[i] == null) | |
{ | |
hasMissingScript = true; | |
break; | |
} | |
} | |
if (hasMissingScript) | |
{ | |
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(childTransform.gameObject); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment