Game Dev Cheat Sheet

Editor errors

The referenced script on this Behaviour (Game Object 'X') is missing!

The exact message

The referenced script on this Behaviour (Game Object 'X') is missing!
Variants of this message
  • The referenced script on this Behaviour is missing!
  • The referenced script (Unknown) on this Behaviour is missing!
  • The referenced script on this Behaviour is missing
  • Missing (Mono Script)

What it means

A component on a GameObject points at a C# script that Unity can no longer resolve. The component slot survives in the scene or prefab and shows as Missing (Mono Script) in the Inspector, but there is nothing behind it. Unity identifies scripts by the GUID in their .meta file rather than by filename, so this is nearly always a broken GUID link rather than a genuinely absent file.

Causes and fixes

Ranked by how often they actually occur, most common first.

  1. The script file was deleted or renamed outside Unity

    Deleting a .cs file while Unity is closed, or renaming it in Explorer without its .meta file, breaks every component referencing it. Renaming the file so it no longer matches the class name inside has the same effect, because Unity requires a MonoBehaviour's file name and class name to match in order to bind them.

    The fix: Restore the script, or remove the dead component. Rename files from inside the Project window rather than in the file system, which keeps the .meta alongside and preserves the GUID.

    Source: Unity Discussions: the referenced script on this Behaviour is missing

  2. The .meta file was lost, so the GUID changed

    Every asset has a .meta file containing the GUID that scenes and prefabs use to reference it. Losing that file makes Unity generate a new GUID on reimport, and every existing reference then points at a GUID nothing has. Version control that ignores .meta files is the usual cause, and it breaks references for everyone who pulls.

    The fix: Restore the original .meta from version control, which restores the GUID and every reference with it. Make sure .meta files are committed: they are not incidental, they are the reference graph.

    The .gitignore rule that matters. Meta files must be tracked, including inside ignored folders.

    # Unity generates these; they must NOT be ignored.
    # Library/, Temp/ and friends are ignored, but their .meta files
    # are not inside those folders, so this rule is about not adding
    # a blanket *.meta exclusion anywhere.
    
    /[Ll]ibrary/
    /[Tt]emp/
    /[Oo]bj/
    /[Bb]uild/
    /[Ll]ogs/
    
    # Never add a line like this:
    # *.meta

    Source: Unity Manual: Meta files and asset serialisation

  3. A compile error means the class does not currently exist

    While the project has compile errors, the types in the failing assembly do not exist, so components referencing them show as missing. This version is temporary and alarming: opening a scene while the project does not compile can appear to have destroyed all your components. They come back when compilation succeeds.

    The fix: Fix the compile errors first and let Unity recompile before doing anything else. Do not save the scene while components show as missing for this reason, because saving can write out the broken state.

    Source: Unity Discussions: missing script caused by unresolved compile errors

  4. A package or asset was removed while still in use

    Removing a package or deleting an imported asset takes its scripts with it, and any object still carrying those components is left with missing references. This often appears on prefabs nobody has opened for months, so the removal and the error can be separated by a long time.

    The fix: Reinstall the package if the components are still wanted, or strip the dead components if they are not. Unity provides a built-in command for the latter, described below.

    Source: Unity Discussions: missing script after removing an imported asset package

  5. The script does not derive from MonoBehaviour

    A class that does not inherit from MonoBehaviour cannot be a component. If a script is changed to remove that inheritance while instances of it are attached to objects, those components can no longer bind and report as missing. The file is present and compiles, which makes this one counter-intuitive.

    The fix: Restore the MonoBehaviour base class if the script is meant to be a component. If it is not, remove the component from the objects carrying it; a plain class belongs in a field, not on a GameObject.

    Source: Unity Manual: MonoBehaviour

How to prevent it

Commit .meta files to version control and never ignore them. They hold the GUIDs that every scene and prefab reference depends on, so losing one breaks references that look nothing like a version control problem.

Rename and move assets from inside Unity's Project window rather than in Explorer or Finder. Unity moves the .meta file with the asset; the file system does not.

Clear compile errors before opening or saving scenes. Components referencing types in a failing assembly show as missing, and saving in that state can persist the damage.

Use Unity's built-in cleanup rather than removing components by hand. GameObject > Remove Missing Scripts strips dead component slots from the selection, and running it on a prefab fixes every instance at once.

Unity version differences

The message is stable across supported versions. The Remove Missing Scripts menu command has been available since Unity 2019.1; before that, removing dead components required a script or hand-editing the scene file.

Sources

Frequently asked questions

How do I find which GameObject has the missing script?
The message names the GameObject in brackets where it can. Clicking the console entry selects the object in the Hierarchy. For objects inside prefabs or in scenes that are not open, searching the project for the text Missing in the Hierarchy search does not work; opening each prefab and looking for Missing (Mono Script) in the Inspector does, as does searching the scene file in a text editor for a script reference with a GUID that no .meta file contains.
Is this error harmful, or can I ignore it?
The component does nothing, so whatever behaviour it provided is absent. If the object still works, the component was probably redundant and can be removed. If something is broken, this error is likely the reason. Either way it is worth resolving, because missing components accumulate and make it harder to spot the one that matters.
How do I remove all missing scripts at once?
Select the affected objects and use GameObject > Remove Missing Scripts from the menu bar. Running it on a prefab asset fixes every instance of that prefab. For a whole project, a small Editor script iterating prefabs and calling GameObjectUtility.RemoveMonoBehavioursWithMissingScript does the same thing in bulk.
The script file is definitely there, so why does Unity say it is missing?
Because Unity resolves scripts by the GUID in the .meta file, not by filename. A file that was re-added without its original .meta has a new GUID, so existing references still point at the old one. It is also worth checking that the file name matches the class name exactly and that the class still derives from MonoBehaviour.
Why did this appear for everyone after a merge?
Almost certainly a .meta file was lost or regenerated during the merge, changing an asset's GUID. Restoring the original .meta from history restores every reference at once. This is the single strongest argument for treating .meta files as first-class tracked files rather than build noise.

Last updated: