0
\$\begingroup\$

I have a large project in Unity and I would like to change the font for every TextMeshPro Object in every scene. I've tried changing the "Default Font Asset" in Edit > TextMesh Pro > Settings but it doesn't work as I wished. It change the font of newly created TextMeshPro Object but old one have still the old font.

The working solution I found is renaming my Font Asset file. For example, my old font was "LiberationSans SDF.asset" and my new font is "Almendra-Regular SDF.asset" so I just rename "Almendra-Regular SDF.asset" into "LiberationSans SDF.asset" and it works.

However, this solution is... dirty. Is there a better web to change the font of every TextMeshPro Object in every Scene ?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I think your solution of renaming the file in your file explorer is quite good, actually. You can then rename it back to the name you want inside Unity, and all the assets will point to the correct font.

The reason is that Unity assets reference each other not by name, but by GUID. The GUID is stored in the .meta file of the same name that you'll find alongside the asset file in your file explorer (though you may need to enable showing hidden files to see it).

By renaming the source file, you pair your new font asset with the existing asset's GUID, so all the existing files point to it now.

You could accomplish something similar by just renaming LiberationSans.ttf.meta to your new font's name (and placing it in the same folder). Then the existing GUID would point to your new font, and Unity would generate a new GUID for LiberationSans.ttf upon noticing that it doesn't have a .meta file of its own anymore.

Or, if you have settings on your new font asset that you want to preserve, you can open up the two assets' meta files and swap their GUIDs. Here's what LiberationSans.ttf.meta looks like for me:

fileFormatVersion: 2
guid: e3265ab4bf004d28a9537516768c1c75
timeCreated: 1484171297
licenseType: Pro
TrueTypeFontImporter:
  serializedVersion: 2
  fontSize: 16
  forceTextureCase: -2
  characterSpacing: 1
  characterPadding: 0
  includeFontData: 1
  use2xBehaviour: 0
  fontNames: []
  fallbackFontReferences: []
  customCharacters: 
  fontRenderingMode: 0
  userData: 
  assetBundleName: 
  assetBundleVariant: 

So copying that second line into your new asset's .meta, and vice versa, will swap their IDs so that any reference that had pointed to one now points to the other.

You could also write an editor script that uses the UnityEditor.AssetDatabase class to iterate over all scenes/prefabs/etc. searching for font references to remap, which would be a more robust/less hacky solution. But for a one-off global replace, mucking with the files this way will probably save you hours of debugging such a script.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .