Skip to content

Instantly share code, notes, and snippets.

@simonwittber
Created January 14, 2021 07:15
Show Gist options
  • Save simonwittber/cc066c383636796c666941ead719b1fb to your computer and use it in GitHub Desktop.
Save simonwittber/cc066c383636796c666941ead719b1fb to your computer and use it in GitHub Desktop.
Cleanup missing scripts on Prefabs.
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