├── .gitattributes
├── package.json.meta
├── LICENSE.meta
├── README.md.meta
├── Editor.meta
├── Editor
├── MissingScriptsFinder.cs.meta
└── MissingScriptsFinder.cs
├── package.json
├── LICENSE
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/package.json.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1ed21fe9a9ce4128a7002abe7c375c57
3 | timeCreated: 1725131000
--------------------------------------------------------------------------------
/LICENSE.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 73b038fb374744e96812ce3238fcbc24
3 | DefaultImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/README.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0a535a6b5fc3d44118c2193a55e05783
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 163620b1f23454010abb61d2da1e6574
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/MissingScriptsFinder.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c17099b28e33349c7b729b47776f2621
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "unity-missing-scripts-finder",
3 | "version": "1.2.2",
4 | "description": "A Unity Editor tool for finding and removing missing scripts from your scenes and prefabs.",
5 | "author": "RimuruDev",
6 | "license": "MIT",
7 | "main": "MissingScriptsFinder.cs",
8 | "scripts": {},
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/RimuruDev/Unity-MissingScriptsFinder.git"
12 | },
13 | "keywords": [
14 | "unity",
15 | "editor",
16 | "tool",
17 | "missing-scripts",
18 | "prefabs",
19 | "gameobjects",
20 | "rimurudev",
21 | "rimuru-dev"
22 | ],
23 | "bugs": {
24 | "email": "rimuru.dev@gmail.com",
25 | "url": "https://github.com/RimuruDev/Unity-MissingScriptsFinder/issues"
26 | },
27 | "homepage": "https://github.com/RimuruDev/Unity-MissingScriptsFinder",
28 | "dependencies": {}
29 | }
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Rimuru
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Unity Missing Scripts Finder
2 |
3 | This Unity Editor tool helps you find and remove missing scripts from your scene. It provides a user-friendly interface to identify GameObjects with missing scripts and offers the option to delete them.
4 |
5 | ## Features
6 |
7 | - **Find Missing Scripts in Scene**: Scans the current scene for GameObjects with missing scripts and logs their locations.
8 | - **Delete Missing Scripts in Scene**: Removes all missing scripts from GameObjects in the scene.
9 | - **Find Missing Scripts in Prefabs**: Scans all prefabs in the project for missing scripts and logs their locations. You can click on the log entries to quickly locate the problematic prefab in the project.
10 |
11 | ## Installation
12 |
13 | ### Option 1: Install via Unity Package Manager
14 |
15 | 1. Open Unity and go to `Window` > `Package Manager`.
16 | 2. Click the `+` button in the top-left corner.
17 | 3. Select `Add package from git URL...`.
18 | 4. Enter the following URL:
19 | ```
20 | https://github.com/RimuruDev/Unity-MissingScriptsFinder.git
21 | ```
22 | 5. Click `Add` to install the package.
23 |
24 | ### Option 2: Install via Release Package
25 |
26 | 1. Download the latest `.unitypackage` file from the [Releases](https://github.com/RimuruDev/Unity-MissingScriptsFinder/releases) page.
27 | 2. In Unity, go to `Assets` > `Import Package` > `Custom Package...`.
28 | 3. Select the downloaded `.unitypackage` file and import it into your project.
29 |
30 | ## Usage
31 |
32 | 1. Open Unity and go to the menu bar.
33 | 2. Navigate to `RimuruDev Tools` > `Find Missing Scripts`.
34 | 3. In the window that appears, you have three options:
35 | - **Find Missing Scripts in Scene**: Click this button to scan the scene and log all GameObjects with missing scripts.
36 | - **Delete All Missing Scripts in Scene**: Click this button to remove all missing scripts from the scene.
37 | - **Find Missing Scripts in Prefabs**: Click this button to scan all prefabs in the project for missing scripts. Each logged message allows you to click on it to ping and locate the prefab in the project window.
38 |
39 |
40 |
41 |
42 |
43 | ## Scene
44 |
45 | 
46 |
47 | ## Prefabs
48 |
49 |
50 |
51 |
52 | ## Contact
53 |
54 | - **Email**: [rimuru.dev@gmail.com](mailto:rimuru.dev@gmail.com)
55 | - **GitHub**: [RimuruDev](https://github.com/RimuruDev)
56 | - **LinkedIn**: [rimuru](https://www.linkedin.com/in/rimuru/)
57 |
58 | ## License
59 |
60 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
61 |
62 | ---
63 |
--------------------------------------------------------------------------------
/Editor/MissingScriptsFinder.cs:
--------------------------------------------------------------------------------
1 | // ReSharper disable all
2 |
3 | // **************************************************************** //
4 | //
5 | // Copyright (c) RimuruDev. All rights reserved.
6 | // Contact:
7 | // - Gmail: rimuru.dev@gmail.com
8 | // - GitHub: https://github.com/RimuruDev
9 | // - LinkedIn: https://www.linkedin.com/in/rimuru/
10 | //
11 | // **************************************************************** //
12 |
13 | #if !UNITY_2020_OR_NEWER && !UNITY_2020_1_OR_NEWER
14 | using System.Linq;
15 | #endif
16 |
17 | using UnityEditor;
18 | using UnityEngine;
19 | using UnityEditor.SceneManagement;
20 |
21 | namespace AbyssMoth
22 | {
23 | public sealed class MissingScriptsFinder : EditorWindow
24 | {
25 | [MenuItem("RimuruDev Tools/Find Missing Scripts")]
26 | public static void ShowWindow() =>
27 | GetWindow("Find Missing Scripts");
28 |
29 | private void OnGUI()
30 | {
31 | if (GUILayout.Button("Find Missing Scripts in Scene"))
32 | FindMissingScriptsInScene();
33 |
34 | if (GUILayout.Button("Delete All Missing Scripts in Scene"))
35 | DeleteAllMissingScriptsInScene();
36 |
37 | if (GUILayout.Button("Find Missing Scripts in Prefabs"))
38 | FindMissingScriptsInPrefabs();
39 | }
40 |
41 | private static GameObject[] FindGameObjects(bool includeInactive = true)
42 | {
43 | #if UNITY_6000_0_OR_NEWER
44 | var inactiveMode = includeInactive
45 | ? FindObjectsInactive.Include
46 | : FindObjectsInactive.Exclude;
47 |
48 | return Object.FindObjectsByType(inactiveMode, FindObjectsSortMode.InstanceID);
49 | #elif UNITY_2020_OR_NEWER || UNITY_2020_1_OR_NEWER
50 | return Object.FindObjectsOfType(includeInactive);
51 | #else
52 | if (includeInactive)
53 | {
54 | return Resources.FindObjectsOfTypeAll().Cast().ToArray();
55 | }
56 | else
57 | {
58 | return Object.FindObjectsOfType();
59 | }
60 | #endif
61 | }
62 |
63 |
64 | private static void FindMissingScriptsInScene()
65 | {
66 | var objects = FindGameObjects();
67 | var missingCount = 0;
68 |
69 | foreach (var go in objects)
70 | {
71 | var components = go.GetComponents();
72 | foreach (var component in components)
73 | {
74 | if (component == null)
75 | {
76 | missingCount++;
77 | Debug.Log($"Missing script found in GameObject: {GetFullPath(go)}", go);
78 | }
79 | }
80 | }
81 |
82 | Debug.Log(missingCount == 0
83 | ? "No missing scripts found in the scene."
84 | : $"Found {missingCount} GameObjects with missing scripts in the scene.");
85 | }
86 |
87 | private static void DeleteAllMissingScriptsInScene()
88 | {
89 | var objects = FindGameObjects();
90 | var removedCount = 0;
91 |
92 | foreach (var go in objects)
93 | {
94 | var components = go.GetComponents();
95 | foreach (var component in components)
96 | {
97 | if (component == null)
98 | {
99 | GameObjectUtility.RemoveMonoBehavioursWithMissingScript(go);
100 | removedCount++;
101 | }
102 | }
103 | }
104 |
105 | Debug.Log(removedCount == 0
106 | ? "No missing scripts found to delete in the scene."
107 | : $"Deleted {removedCount} missing scripts in the scene.");
108 |
109 | EditorSceneManager.MarkAllScenesDirty();
110 | }
111 |
112 | private static void FindMissingScriptsInPrefabs()
113 | {
114 | var prefabGUIDs = AssetDatabase.FindAssets("t:Prefab");
115 | var missingCount = 0;
116 |
117 | foreach (var guid in prefabGUIDs)
118 | {
119 | var path = AssetDatabase.GUIDToAssetPath(guid);
120 | var prefab = AssetDatabase.LoadAssetAtPath(path);
121 | var components = prefab.GetComponentsInChildren(true);
122 |
123 | foreach (var component in components)
124 | {
125 | if (component == null)
126 | {
127 | missingCount++;
128 | Debug.Log($"Missing script found in Prefab: {path}", prefab);
129 | }
130 | }
131 | }
132 |
133 | Debug.Log(missingCount == 0
134 | ? "No missing scripts found in any prefabs."
135 | : $"Found {missingCount} prefabs with missing scripts.");
136 | }
137 |
138 | private static string GetFullPath(GameObject go)
139 | {
140 | var path = "/" + go.name;
141 | while (go.transform.parent != null)
142 | {
143 | go = go.transform.parent.gameObject;
144 | path = "/" + go.name + path;
145 | }
146 |
147 | return path;
148 | }
149 | }
150 | }
151 |
--------------------------------------------------------------------------------