Warning: The referenced script on this Behaviour is missing!

Feedback and Discussion about material presented on The Ant Ranch
User avatar
Posts: 11
Joined: 29 Aug 2014, 15:56
Location: Invergordon, Highlands of Scotland

Warning: The referenced script on this Behaviour is missing!

Postby OboShape » 21 Jan 2015, 19:29

Its a common and frustrating one, we've all came across it when starting out when tinkering with scripts etc when we have a few things going on in our projects, and it can be a frustrating search to find the source of the problem..

This usually comes up, when you either edit scripts, delete or move them around the place.

Don't go pulling your hair out, or delete the whole lot just yet before trying this :)

its from the Unity Wiki page...

so lets begin with you opening the problematic project and scene :

at the root of your project, directly under assets, create a new folder called 'Editor'
and in that folder create a new C# script called 'FindMissingScriptsRecursively' (watch the spelling and Case!!)

open that script up for editing...

delete everything in it, then copy this entire code into that script, and save script.

Code: Select all

using UnityEngine;
using UnityEditor;
public class FindMissingScriptsRecursively : EditorWindow
    static int go_count = 0, components_count = 0, missing_count = 0;
    public static void ShowWindow()
    public void OnGUI()
        if (GUILayout.Button("Find Missing Scripts in selected GameObjects"))
    private static void FindInSelected()
        GameObject[] go = Selection.gameObjects;
        go_count = 0;
        components_count = 0;
        missing_count = 0;
        foreach (GameObject g in go)
        Debug.Log(string.Format("Searched {0} GameObjects, {1} components, found {2} missing", go_count, components_count, missing_count));
    private static void FindInGO(GameObject g)
        Component[] components = g.GetComponents<Component>();
        for (int i = 0; i < components.Length; i++)
            if (components[i] == null)
                string s = g.name;
                Transform t = g.transform;
                while (t.parent != null)
                    s = t.parent.name +"/"+s;
                    t = t.parent;
                Debug.Log (s + " has an empty script attached in position: " + i, g);
        // Now recurse through each child GO (if there are any):
        foreach (Transform childT in g.transform)
            //Debug.Log("Searching " + childT.name  + " " );

this script will now put a new menu item under Window > FindMissingScriptsRecursively

ok once thats saved, run your game until you get the error....
pause the game... (not stop)

go to Window > FindMissingScriptsRecursively
this will pop up a new window.

select all the game objects in your heirarchy, then in that window that popped up, press the only button thats there for 'Find Missing Scripts in selected GameObjects'

now, this will search all the selected game objects and tell you where there is a missing reference. and the results will be shown in the console window.

you may see something like this (just an error that ive made up)
done_explosion_enemy(Clone) has an empty script attached in position: 3
Searched 43 GameObjects, 136 components, found 2 missing

when looking at that, since your game is paused you can highlight the mentioned game object within your heirarchy that listed on first line. (in our example case : done_explosion_enemy(Clone))
so in our example error, its saying that there is a missing script in position 3, since you have highlighted the game object, its components are visible in the inspector... so position 3 is the third component down from the top (ie transform component is 1st etc)

you will see a yellow triangle warning on the component indicating a problem..

so you can now fix it, by either checking your spelling the script and class exactly the same, or drag and drop the mising script onto the component again :)

Hope it helps someone...

Powered by Nescafe
Non illigitamus carborundum

Return to “Tutorials & Examples”

Who is online

Users browsing this forum: No registered users and 1 guest