- Home /
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?
I don't think there is way to search for that... Can I give points for the intern joke? :-)
Answer by SimTex · Mar 07, 2010 at 09:45 PM
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[i] == null)
{
Debug.Log(g.name + " has an empty script attached in position: " + i);
}
}
}
}
} }
I reposted this into the wiki:
http://www.unifycommunity.com/wiki/index.php?title=Find$$anonymous$$issingScripts
@Clement if you agree with this answer you should also accept it as the correct one.
Answer by lowbloodsugar · Mar 08, 2010 at 08:15 PM
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[i] == null)
{
Debug.Log(g.name + " has an empty script attached in position: " + i);
}
}
}
} }}
@Clement, please don't repost the same answers small changes can be done on the original answer if you simply ask via comment.
then what are we going to do with this script,put where i mean? need to attach to any or do what,as cannot attach to $$anonymous$$issing ($$anonymous$$ono Script)"
i think $$anonymous$$issing ($$anonymous$$ono Script)" is not in none of those script,So how any solution?
Answer by daniel254973 · Jan 17, 2019 at 04:57 PM
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[i] == null)
{
Debug.Log(t.name + " has an empty script attached in position: " + i, t.gameObject);
}
}
}
}
}
}
Answer by oliver_unity892 · Mar 27, 2020 at 09:14 AM
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
He said to save it in the folder Assets/Editor, which should be in your project by default. You select it from the "Window" dropdown in the Unity Editor.
Answer by RickshawDerpyDerp · Dec 25, 2020 at 02:44 AM
I thought somebody had a solution to recover the name of the missing script?