Skip to content

Instantly share code, notes, and snippets.

@UCh
Created March 24, 2017 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UCh/5a72f16d627212e7a1dd62f0f74c2257 to your computer and use it in GitHub Desktop.
Save UCh/5a72f16d627212e7a1dd62f0f74c2257 to your computer and use it in GitHub Desktop.
[MenuItem("Edit/Search missing references in prefabs (Full project)", false, 50)]
public static void FindMissingReferencesInProject()
{
UnityEngine.Debug.Log("Starting search for missing components in project prefabs");
var paths = AssetDatabase.FindAssets("t:prefab").ToList().Select(guid => AssetDatabase.GUIDToAssetPath(guid));
foreach (var path in paths)
{
var go = AssetDatabase.LoadAssetAtPath<GameObject>(path);
var components = go.GetComponents<Component>();
var componentsChilds = go.GetComponentsInChildren<Component>();
int array1OriginalLength = components.Length;
Array.Resize<Component>(ref components, array1OriginalLength + componentsChilds.Length);
Array.Copy(componentsChilds, 0, components, array1OriginalLength, componentsChilds.Length);
foreach (var component in components)
{
if (component == null)
{
UnityEngine.Debug.LogError("MISSING COMPONENT: " + path);
break;
}
}
}
UnityEngine.Debug.Log("Search completed");
}
@UCh
Copy link
Author

UCh commented Mar 24, 2017

This editor script for Unity locates all prefabs in the project that has a missing reference and output the path in the console

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment