Hello everyone,
Does anyone know how to remove all missing monobehaviours in the scene and all prefabs by editor script ? I did do some search but still not find a way to do. Is it doable ? Can anyone point me to the right direction ?
Thanks a lot.
Hello everyone,
Does anyone know how to remove all missing monobehaviours in the scene and all prefabs by editor script ? I did do some search but still not find a way to do. Is it doable ? Can anyone point me to the right direction ?
Thanks a lot.
You can use the FindMissingScriptsRecursively.cs to find all missing Behaviours in the scene.
http://wiki.unity3d.com/index.php?title=FindMissingScripts (wiki.unity3d.com is offline now)
Just select all objects / or the object root and open Window/FindMissingScriptsRecursively
I can find it, actually. Just donât know a way to remove those missing behaviours but manually do it one by one.
Thanks for your help anyway
You could add somting like DestroyImmediate(components*); to line 51 of the script , that should delete the missing component entry (NOT TESTED USE WITH CAUTION)*
Tried that before, but those components are already null, you can not destroy them ![]()
Even after removing the interpolated strings so I can run it on the version of Mono weâre using, that didnât work for me in 2017.3. It does clearly remove many behaviours (reading the diff of the scene), but quite a few then get added back when you hit play with the message:
CheckConsistency: GameObject does not reference component MonoBehaviour. Fixing.

Looks like I have to go through them all manually ![]()
Donât change Nested Prefab library mid project people. It makes for a long day.
Edit:
It actually did delete them, it just didnât print properly. Thanks for the code mate ![]()
hehe no problem, glad it helped ![]()
Did you find any way to fix that error? Iâm having the same issue.
No, itâs on the very long list of things weâve just learned not to care too much about. There are many such things in the life of an app developer. Our iTunes Connect console is filled with dead apps that we have no way to remove. Our older codebases are filled with zombie monobehaviours. Xcode likes to make a new provisioning profile every time you breathe. The only way forward is just to not care and keep on shipping stuff.
This answer: http://answers.unity.com/answers/1614734/view.html
Which relies on GameObjectUtility.RemoveMonoBehavioursWithMissingScript and PrefabUtility.GetCorrespondingObjectFromSource (available in 2019.1)
Hello!
Sadly the Code does not find any Missing Scripts :-/
int count = GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(gameObject);
Debug.Log("Found {count} missing scripts");
count = GameObjectUtility.RemoveMonoBehavioursWithMissingScript(gameObject);
Debug.Log(âRemoved {count} missing scriptsâ);
Count is always 0 even if gameObject does have ânull-scriptsâ.
With the old method it still finds the missing scripts but the âprop.DeleteArrayElementAtIndexâ ist nit supported any more in Unity 2019⌠Is there another way to delete missing scripts from the serializedObject-Property âm_Componentâ?
Thanks!
Hi @Schmaggis , which version of Unity are you using?
I just tried the code you are using and this is the result I am getting with 2019.2.15f1:
Do you mind to share the script? this new Prefab workflow API confused me
public class RemoveMissingScripts : Editor
{
[MenuItem("GameObject/Remove Missing Scripts")]
public static void Remove()
{
var objs = Resources.FindObjectsOfTypeAll<GameObject>();
int count = objs.Sum(GameObjectUtility.RemoveMonoBehavioursWithMissingScript);
Debug.Log($"Removed {count} missing scripts");
}
}
Thank you so much Brogan89, you are a lifesaver, Iâve seen so many complicated methods that just couldnât get the job done and you have found the simplest solution. Thanks again and God bless!
FYI, non of those presented options here works in some edge cases.
This is the result of Brogan89 script, nothing helps in my case ![]()
I think I need to go through 600 missing references manually ![]()

Yeah I just had this happen as well. It removed the scripts from the prefabs but once I saved it reverted all the missing scripts back ![]()
However, I have another window I made which may be of worth to you. It just helps find the prefabs or whatever with missing scripts.
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
public class FindMissingScriptsWindow : EditorWindow
{
[MenuItem("Window/Missing Script Window")]
private static void Init()
{
GetWindow<FindMissingScriptsWindow>("Missing Script Finder").Show();
}
public List<GameObject> results = new List<GameObject>();
private void OnGUI()
{
if (GUILayout.Button("Search Project"))
SearchProject();
if (GUILayout.Button("Search scene"))
SearchScene();
if (GUILayout.Button("Search Selected Objects"))
SearchSelected();
// src: https://answers.unity.com/questions/859554/editorwindow-display-array-dropdown.html
var so = new SerializedObject(this);
var resultsProperty = so.FindProperty(nameof(results));
EditorGUILayout.PropertyField(resultsProperty, true);
so.ApplyModifiedProperties();
}
private void SearchProject()
{
results = AssetDatabase.FindAssets("t:Prefab")
.Select(AssetDatabase.GUIDToAssetPath)
.Select(AssetDatabase.LoadAssetAtPath<GameObject>)
.Where(x => IsMissing(x, true))
.Distinct()
.ToList();
}
private void SearchScene()
{
results = FindObjectsOfType<GameObject>()
.Where(x => IsMissing(x, false))
.Distinct()
.ToList();
}
private void SearchSelected()
{
results = Selection.gameObjects
.Where(x => IsMissing(x, false))
.Distinct()
.ToList();
}
private static bool IsMissing(GameObject go, bool includeChildren)
{
var components = includeChildren
? go.GetComponentsInChildren<Component>()
: go.GetComponents<Component>();
return components.Any(x => x == null);
}
}
I have an error message that just lists the missing script, âError while saving prefab: âAssets/XXXX/XXXXX/etcââ and says âYou are trying to save a Prefab with a missing script. This is not allowed.â Well, I found its folder. Couldnât I just go into the asset folder and delete its file? (Edit: All Iâve done so far is try importing it, beyond that I havenât done anything with the asset except download it from the assetstore)