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.
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
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: # *.metaA 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
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
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.
Related errors
- Script class cannot be foundWhy Unity refuses to add a script component, ranked from compile errors and name mismatches to namespaces and abstract classes, with the fix for each.
- UnassignedReferenceExceptionWhy Unity says a variable has not been assigned, including the case where you did assign it, and how prefabs and scene references cause it.
- MissingReferenceExceptionWhy Unity says an object has been destroyed but you are still accessing it, how destroyed objects differ from null, and the four causes worth checking.
Related tools
Sources
- Unity Manual: Meta files and asset serialisation
- Unity Scripting API: GameObjectUtility.RemoveMonoBehavioursWithMissingScript
- Unity Discussions: the referenced script on this Behaviour is missing
- Unity Discussions: missing script caused by unresolved compile errors
- Unity Discussions: missing script after removing an imported asset package
- Unity Manual: MonoBehaviour