Search Unity

Loading/creating TMP_FontAsset at runtime from StreamingAssets

Discussion in 'UGUI & TextMesh Pro' started by Manufacture43, Feb 21, 2020.

  1. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140
    Hi,

    I'm trying to add community based localization to narrative games from a client. In many cases users would need to add nice fonts that match the style of the game.

    Is it possible to load new fonts at runtime from StreamingAssets?

    I see that there is constructor for TMP_FontAsset that takes a Unity.Font but I didn't see any way of loading a Unity.Font at runtime, except from the OS installed fonts, which is quite limited and doesn't really allow for pretty fonts.

    Best,
     
  2. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140
    Well, it ended up braindead easy. While it is documented that the UnityEngine.Font constructor takes the name of an OS installed font, reading the source on github actually shows that it can be a path too! (line 312)