how do you delete missing behaviours that are invisible in the inspector?

this one’s been eluding me for a while:


that’s the object
6376392--709968--upload_2020-10-2_11-3-11.png

i had the solution all along:

using UnityEditor;
using UnityEngine;

public class RemoveMissingMonoFromSelectedSceneObjects : MonoBehaviour
{
    [MenuItem("Tools/Remove Missing Monos From Selected Scene Objects")]
    public static void CleanupSelectedSceneObjects()
    {
        foreach (var s in Selection.gameObjects)
        {
#if UNITY_2018_1_OR_NEWER
            GameObjectUtility.RemoveMonoBehavioursWithMissingScript(s);
            foreach (Transform t in s.transform)
            {
                GameObjectUtility.RemoveMonoBehavioursWithMissingScript(t.gameObject);
            }
            EditorUtility.SetDirty(s);
#else
            Debug.LogError("only works in 2018 or newer");
#endif
        }
    }
}
1 Like