"Clear Dynamic Data on Build" Doesn't Clear Atlas for Some Fonts

Hi,

For some reason, some of our dynamic fonts gets in the build with an atlas and they’re taking 1MB for each one (I know, I know, it’s not that much; but I’d prefer 0x0 atlas).

We’re using both TMP and TextCore. This is not happening for any TextCore fonts, only for some TMP fonts (right now, 4 of them and we’ve 16 fonts). We also wrote a IPreprocessBuildWithReport script to clear font data; but it seems, even all the fonts says their atlas size is 0x0, after the build we see 4 fonts as 1024x1024 (1MB I mean) in the build report.

The fonts are located in Resources/Fonts/TMP directory; and for example, right now only one of them has characters in the character table (only 2 atm). But after the build, this font and other 3 fonts creates their atlases.

I am suspecting that this is caused by scene building (one scene is using these fonts with active UI elements (canvas)). We’ll eventually move all of our remaining Unity UI to UI Toolkit; but not now. So we won’t have such problem in the future.

Can anyone suggest anything? We tried recreating font assets, disabling/enabling “Clear Dynamic Data on Build”, clearing atlas manually, build process scripting. Nothing solves this =/ This happens on iOS and Android builds. Didn’t try other platforms.

This is the IPreprocessBuildWithReport script we used.

public class DynamicFontAtlasPreBuildProcessor : IPreprocessBuildWithReport
	{
		public int  callbackOrder                          => 999999;
		public void OnPreprocessBuild(BuildReport report)
		{
			var type   = $"t:TMP_FontAsset";
			var assets = AssetDatabase.FindAssets(type);
			foreach(var asset in assets)
			{
				var path = AssetDatabase.GUIDToAssetPath(asset);
				var font = AssetDatabase.LoadAssetAtPath<TMPro.TMP_FontAsset>(path);

				if(font.atlasPopulationMode == TMPro.AtlasPopulationMode.Dynamic)
					font.ClearFontAssetData(setAtlasSizeToZero: true);
			}
		}
	}