Thursday, September 29, 2022
HomeGame Developmentunity - Change the "Font Asset" of each TextMeshPro object

unity – Change the “Font Asset” of each TextMeshPro object


I believe your resolution of renaming the file in your file explorer is sort of good, truly. You’ll be able to then rename it again to the identify you need inside Unity, and all of the belongings will level to the right font.

The reason being that Unity belongings reference one another not by identify, however by GUID. The GUID is saved within the .meta file of the identical identify that you’re going to discover alongside the asset file in your file explorer (although chances are you’ll must allow exhibiting hidden recordsdata to see it).

By renaming the supply file, you pair your new font asset with the present asset’s GUID, so all the present recordsdata level to it now.

You might accomplish one thing comparable by simply renaming LiberationSans.ttf.meta to your new font’s identify (and putting it in the identical folder). Then the present GUID would level to your new font, and Unity would generate a brand new GUID for LiberationSans.ttf upon noticing that it would not have a .meta file of its personal anymore.

Or, if in case you have settings in your new font asset that you simply need to protect, you’ll be able to open up the 2 belongings’ meta recordsdata and swap their GUIDs. This is what LiberationSans.ttf.meta seems like for me:

fileFormatVersion: 2
guid: e3265ab4bf004d28a9537516768c1c75
timeCreated: 1484171297
licenseType: Professional
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 in order that any reference that had pointed to 1 now factors to the opposite.

You might additionally write an editor script that makes use of the UnityEditor.AssetDatabase class to iterate over all scenes/prefabs/and so forth. looking for font references to remap, which might be a extra sturdy/much less hacky resolution. However for a one-off international exchange, mucking with the recordsdata this fashion will most likely prevent hours of debugging such a script.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments