- Home /
Script for locating missing files?
Is there a script for finding missing files within prefabs?
I took several prefabs from another project (the angrybots demo) and put them into another project that I'm working with. The prefabs couldn't find their missing scripts or other elements even though I had them in the same place as they were in the demo project.
I'm just wondering if there is a script to automate the process of finding them all.
Do those prefabs have names and are they in the assests folder?
All the core files are there, but it just doesn't re-link to them. I'm having to re-link them all with the respective game objects.
Answer by Hannibalov · Oct 22, 2012 at 08:59 AM
I'm using this script:
using UnityEngine;
using UnityEditor;
public class FindMissingScripts : EditorWindow {
[MenuItem("Window/FindMissingScripts")]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(FindMissingScripts));
}
public void OnGUI()
{
if (GUILayout.Button("Find Missing Scripts in selected prefabs"))
{
FindInSelected();
}
}
private static void FindInSelected()
{
GameObject[] go = Selection.gameObjects;
int go_count = 0, components_count = 0, missing_count = 0;
foreach (GameObject g in go)
{
go_count++;
Component[] components = g.GetComponents<Component>();
for (int i = 0; i < components.Length; i++)
{
components_count++;
if (components[i] == null)
{
missing_count++;
Debug.Log(g.name + " has an empty script attached in position: " + i);
}
}
}
Debug.Log(string.Format("Searched {0} GameObjects, {1} components, found {2} missing", go_count, components_count, missing_count));
}
}
I hope this is what you are looking for. I won't take the credit, since I found it some time ago, but I can't remember where
Thanks for the script. I actually found this on the unity wiki I think it was or something like that. If re-linked some of the scripts but not all of them. Thank, though.