Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

TextMesh Pro Renaming the material and atlas embedded in a TMP .asset

Discussion in 'UGUI & TextMesh Pro' started by cellarmation, Nov 8, 2019.

  1. cellarmation

    cellarmation

    Joined:
    Jan 17, 2015
    Posts:
    30
    If you use the Font Asset Creator to make a TextMeshPro .asset from a font you get a .asset file that has an embedded material and atlas.

    A while ago I created a font asset then renamed it when I changed how I was using it. It seems that the material and atlas embedded in the file have the original asset name burnt into their names. Is there any way to rename these or force them to refresh their name?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    As far as I know, this is not possible in the Editor. It should be possible via some Editor script / tool using the AssetDatabase class and functions.

    However, if you only need to do this once, you could cheat and simply edit the font asset file. In the font asset file look for Material: and then m_Name: and then Texture2D: and again m_Name: to rename those sub objects.
     
  3. cellarmation

    cellarmation

    Joined:
    Jan 17, 2015
    Posts:
    30
    Editing the .asset manually was easy, thanks!
     
    Stephan_B likes this.
  4. WookieWookie

    WookieWookie

    Joined:
    Mar 10, 2014
    Posts:
    35
    @Stephan_B I'd like to be able to do this in a large project right now to do a gamewide font swap quickly and easily. I've had a realization that you may already have had:

    If I rename my original fonts (TTF/OTF files) to TitleFont, BodyFont, etc. to begin with, I'll end up with a TitleFont atlas and TitleFont material embedded. Then, if I want to use a different title font in my game, all I have to do is regenerate my TitleFont atlas with glyphs from the new font and adjust the TMP asset settings. This way I can avoid editing every last prefab in the game manually to achieve the font swap.

    I can currently rename my title font asset and its related material variants to TitleFont successfully, but I've had no success renaming the embedded child material and atlas. I don't mind editing some asset file in a text editor, but I keep getting fatal errors in Unity when attempting to do so. Would you mind specifying how to do this?
     

    Attached Files:

  5. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,491
    This remains a mess. If you try to build up a set of fonts, the natural inclination might be to copy the Font Asset and customize. But the names of materials and textures are wrong and shared between fonts, so it's pulling glyphs from the wrong atlas coordinates.

    After editing the files directly, you also should go open some other scene and come back. The re-import does not trigger TMP to update all appropriate information.
     
  6. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,491
    In 2021.3 LTS, no matter how many times I try to update this field, it reverts to an earlier value. I quit Unity, I edited the
    sourceFontFileGUID
    fields to match the TTFs for each of several fonts, I removed my Library folder, and yet when I come back, this field is wrong. This screenshot is after I tried to associate it with epgyosho; I don't see any reference to epkyouka or its GUID in the font asset shown here, but the Inspector keeps going back to that value.