- Home /
How to find all missing fonts and fix them
A Unity project has had some changes in font and caused some fonts to be missing in prefabs and components. Is there an easy way to find all of the missing fonts so that we can reattach them?
Answer by GrayLightGames · Nov 05, 2019 at 06:37 PM
Googling returned this site... have you tried this yet? https://www.gamasutra.com/blogs/LiorTal/20141208/231690/Finding_Missing_Object_References_in_Unity.php
Unfortunately the solution in the link did not seem to find missing fonts, but did help in that it helped find missing scripts: ![alt text][1] [1]: /storage/temp/148379-missing-scripts.png
I had found an updated version (for Unity 5.4+) of the gamasutra script at https://gist.github.com/ProG$$anonymous$$/a40acd8ebbb91eb7b2295e65d5eb42c8 and combined it with some of the changes in the gamasutra article's comments. Thank you for sharing, as finding missing scripts is helpful.
I think that for Fonts, I need something that finds missing Properties.
Since the editor is able to find them and show $$anonymous$$issing (Font) ins$$anonymous$$d, I am hoping there is a similar way to do it through an editor script, or maybe just through the editor somewhere.
Fonts seem to be stored in YA$$anonymous$$L as: m_FontData: m_Font: {fileID: value, guid: value, type: value} m_FontSize: etc...
Bummer, do you know which components you're looking for? I just tried pulling Text objects and checking GetInstanceID() for 0 and font for null like the linked script was doing and I got results... I did some testing and if missing, the instance ID is non-zero and the font is null. Little bit clumsy, but it worked for me. You could probably modify it to check all components if they have a font property, then run the check. If you're just targeting Text and a couple other components, just add a couple more if checks on the components and you'll be there. Hope that helps!
foreach (var tempObj in Object.FindObjectsOfType(typeof(GameObject)))
{
GameObject tempGO = (GameObject)tempObj;
Text tempText = tempGO.GetComponent<Text>();
if (tempText != null && tempText.font.GetInstanceID() != 0 && tempText.font == null)
{
Debug.Log(tempText.name + " has font ID " + tempText.font.GetInstanceID() + " " + (tempText.font == null));
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612214409im_/https://answers.unity.com/themes/thub/images/avi.jpg)