x


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?

more ▼

asked Mar 03 '10 at 04:12 AM

lowbloodsugar gravatar image

lowbloodsugar
433 9 11 16

I don't think there is way to search for that... Can I give points for the intern joke? :-)

Mar 03 '10 at 03:09 PM Yorick
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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);
                }
            }

        }
     }
  } 
}
more ▼

answered Mar 07 '10 at 09:45 PM

SimTex gravatar image

SimTex
191 1 2 7

@Clement if you agree with this answer you should also accept it as the correct one.

Mar 09 '10 at 05:01 AM Lipis
(comments are locked)
10|3000 characters needed characters left

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&lt;Component&gt;();
    for (int i = 0; i &lt; components.Length; i++)
    {
        if (components[i] == null)
        {
            Debug.Log(g.name + " has an empty script attached in position: " + i);
        }
    }

}

} }}

more ▼

answered Mar 08 '10 at 08:15 PM

lowbloodsugar gravatar image

lowbloodsugar
433 9 11 16

@Clement, please don't repost the same answers small changes can be done on the original answer if you simply ask via comment.

Mar 09 '10 at 05:03 AM Lipis

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 Missing (Mono Script)"

Jan 13 '12 at 01:30 AM wenhua

where does position:5 means?????

Jan 13 '12 at 01:44 AM wenhua

i think Missing (Mono Script)" is not in none of those script,So how any solution?

Jan 13 '12 at 01:54 AM wenhua
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1675
x348
x132

asked: Mar 03 '10 at 04:12 AM

Seen: 2996 times

Last Updated: Jan 13 '12 at 01:54 AM