Created
January 14, 2021 07:15
-
-
Save simonwittber/cc066c383636796c666941ead719b1fb to your computer and use it in GitHub Desktop.
Cleanup missing scripts on Prefabs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEngine; | |
public class CleanupMissingScriptsHelper | |
{ | |
[MenuItem("Assets/Cleanup Missing Scripts")] | |
private static void CleanupMissingScripts() | |
{ | |
foreach (var i in Selection.gameObjects) | |
{ | |
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(i); | |
var path = AssetDatabase.GetAssetPath(i); | |
var x = (GameObject)PrefabUtility.InstantiatePrefab(i); | |
PrefabUtility.UnpackPrefabInstance(x,PrefabUnpackMode.Completely,InteractionMode.AutomatedAction); | |
AssetDatabase.DeleteAsset(path); | |
PrefabUtility.SaveAsPrefabAsset(x, path); | |
} | |
AssetDatabase.SaveAssets(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment