Searching a project for "Missing (Mono Script)"

I am getting ready to launch a new game and am going over it with a fine toothed comb to make sure everything is correct.

In the editor, a script that has been assigned to an object, but subsequently deleted has the string "Missing (Mono Script)" where the script class/filename should be. Is it possible to search a project to find all missing scripts?

I have tried using GetComponents, but do not know what I should put into the type field. I have also tried using GetComponent with a null string, "Missing, and "Missing (Mono Script)" as the parameter, but that always returns null. Since I do not know the name of the missing scripts, it makes the problem more difficult.

Is there any other approaches to try, other than hiring an intern?

Can be done with some editor scripting:

You need to search all game objects for empty (null) components. This can e.g. be done like this:

Select all objects you want to search for missing scripts and click.

public class FindMissingScripts : EditorWindow {

    [MenuItem("Window/FindMissingScripts")]
    public static void ShowWindow()
    {
        EditorWindow.GetWindow(typeof(FindMissingScripts));
    }

    public void OnGUI()
    {
     if (GUI.Button(new Rect(0.0f, 60.0f, 100.0f, 20.0f), "Find Missing Scripts"))
     {
        GameObject[] go = Selection.gameObjects;
        foreach (GameObject g in go)
        {

            Component[] components = g.GetComponents<Component>();
            for (int i = 0; i < components.Length; i++)
            {
                if (components *== null)*
 *{*
 *Debug.Log(g.name + " has an empty script attached in position: " + i);*
 *}*
 *}*
 *}*
 *}*
 *}* 
*}*
*```*

That works great! Here are the small changes I had to make to get it to work on my machine (Added using directive and changed MenuItem entry to have window prefix). Save the script as "FindMissingScripts.js"

Clement

using UnityEngine;
using UnityEditor;
public class FindMissingScripts : EditorWindow {

`[MenuItem(“Window/FindMissingScripts”)]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(FindMissingScripts));
}

public void OnGUI()
{
if (GUI.Button(new Rect(0.0f, 60.0f, 100.0f, 20.0f), “Find Missing Scripts”))
{
GameObject go = Selection.gameObjects;
foreach (GameObject g in go)
{

    Component[] components = g.GetComponents<Component>();
    for (int i = 0; i < components.Length; i++)
    {
        if (components *== null)*

{
Debug.Log(g.name + " has an empty script attached in position: " + i);
}
}
}
} }}
`


Due this question still is the first on google looking for missing component’s search I have improved it.
It looks for missing components on every GameObject and child GameObject of selected.
Click Console messages to auto-select GameObject with missing component.

using UnityEngine;
using UnityEditor;

public class FindMissingScripts : EditorWindow
{
	[MenuItem("Tools/FindMissingScripts")]
	public static void ShowWindow()
	{
		GetWindow(typeof(FindMissingScripts)).minSize = new Vector2(190f,60f);
		GetWindow(typeof(FindMissingScripts)).maxSize = new Vector2(190f,60f);
	}
	public void OnGUI()
	{
		if (GUI.Button(new Rect(20.0f, 20.0f, 150.0f, 20.0f), "Find Missing Scripts"))
		{
			Transform[] ts = Selection.GetTransforms(SelectionMode.Deep);

			foreach (Transform t in ts)
			{
				Component[] components = t.GetComponents<Component>();
				for (int i = 0; i < components.Length; i++)
				{
					if (components *== null)*
  •  			{*
    
  •  				Debug.Log(t.name + " has an empty script attached in position: " + i, t.gameObject);*
    
  •  			}*
    
  •  		}*
    
  •  	}*
    
  •  }*
    
  • }*
    }

Thanks for the code

I’d like to use this to find objects with missing scripts and, ideally, find some info about what the scripts were/are. However I don’t know where to save the code to make it function.

I have a load of versions of a given prefab which are showing missing scripts, no idea why as all the scripts appear to be there, guess something went screwy with Collaboration.

Any advice you can provide would be appreciated.

Thanks

I thought somebody had a solution to recover the name of the missing script?