Skip to content

Instantly share code, notes, and snippets.

@stonstad
Created September 22, 2020 17:15
Show Gist options
  • Save stonstad/3e6cf12ac4c8355605571787522a0d01 to your computer and use it in GitHub Desktop.
Save stonstad/3e6cf12ac4c8355605571787522a0d01 to your computer and use it in GitHub Desktop.
Locate Unity Assets Which Contain Broken References
using System;
using System.IO;
using UnityEditor;
using UnityEngine;
using System.Linq;
using System.Threading.Tasks;
public class UnityUtils: MonoBehaviour
{
[MenuItem("Tools/Find Broken GUIDs")]
public static void FindBrokenGUIDs()
{
Task task = Task.Run(() =>
{
string searchText = "guid: 00000000000000000000000000000000";
Debug.Log("Searching for '" + searchText + "'");
Debug.Log("Scanning directory " + Environment.CurrentDirectory);
DirectoryInfo directoryInfo = new DirectoryInfo(Environment.CurrentDirectory);
foreach (DirectoryInfo subdirectory in directoryInfo.GetDirectories())
{
if (subdirectory.Name.StartsWith("."))
continue;
if (subdirectory.Name == "obj")
continue;
if (subdirectory.Name == "Library")
continue;
if (subdirectory.Name == "Temp")
continue;
string[] extensions = new string[]
{
".anim",
".asset",
".controller",
".prefab",
".mat",
".meta",
".terrainlayer",
".unity",
};
var files = subdirectory.GetFiles("*", SearchOption.AllDirectories).
Where(a => extensions.Contains(a.Extension)).ToList();
Debug.Log("Scanning " + files.Count + " files");
foreach (FileInfo file in files)
{
string[] lines = File.ReadAllLines(file.FullName);
foreach (string line in lines)
if (line.Contains(searchText))
{
Debug.Log("Broken Link: " + file.FullName);
break;
}
}
Debug.Log("Finished");
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment