Missing Scripts Audit
Broken script components (displayed as Missing (MonoBehaviour)) occur when a script asset file is deleted, renamed, or fails to compile. These dead references slow down editor serialization and trigger console warnings. The MissingScriptRule identifies and resolves these components.
Technical Details: The Serialization Aspect
When a script is attached to a GameObject, Unity stores a reference to its unique GUID and File ID inside the scene asset file. If that script file is deleted or renamed without update:
- The component reference remains in the scene file, but points to a dead GUID.
- The Inspector displays:
Missing (MonoBehaviour) - Script: None - At runtime, Unity logs:
The referenced script on this Behaviour (Game Object 'Player') is missing!
How the Rule Detects Missing Scripts
The scanning engine utilizes C# reflections to scan all components:
Component[] components = gameObject.GetComponents<Component>();
for (int i = 0; i < components.Length; i++)
{
if (components[i] == null)
{
// This is a missing script reference!
// Unity returns null for components with missing script definitions.
}
}
By identifying these null items, the Scanner compiles a list of target GameObjects.
How to Safe-Scrub Broken Scripts
To clear missing scripts from your scene:
- Run a Scan Scene from the Dashboard.
- Review the list of objects marked with Missing Scripts warning.
- Click Fix on a specific row, or click Fix All.
- The system executes
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(gameObject). - This API call cleans the underlying scene file serialization registry, resolving inspector errors immediately.
[!WARNING] Stripping a missing script is permanent! Ensure the script was deliberately deleted rather than failing to compile. If the script was deleted by accident, restore it from your version control system (Git/SVN) instead of fixing it inside the Scanner.