Search Unity

TextMesh Pro Trying to make the atlas readable via editor scripting

Discussion in 'UGUI & TextMesh Pro' started by koen_unity718, Feb 26, 2024.

  1. koen_unity718

    koen_unity718

    Joined:
    Feb 5, 2024
    Posts:
    2
    Been stuck on this for a little while now.
    We are updating and generating tmpro fonts quite often, I'm trying to automatically set the isReadable on the atlas to true.

    To my knowledge there are two ways this can be done.
    1. Using a texture importer
    Code (CSharp):
    1.  TextureImporter ti = AssetImporter.GetAtPath(path) as TextureImporter;
    2.  
    3. // Check if the TextureImporter is not null
    4. if (ti != null)
    5. {
    6.      if (ti.isReadable != isReadable)
    7.      {
    8.          ti.isReadable = isReadable;
    9.          ti.SaveAndReimport();
    10.          UnityEngine.Debug.Log("Set texture at path '" + path + "' as readable: " + isReadable);
    11.      }
    12.      else
    13.      {
    14.          UnityEngine.Debug.Log("Texture at path '" + path + "' is already readable: " + isReadable);
    15.      }
    16. }
    17. else
    18. {
    19.      UnityEngine.Debug.LogWarning("Failed to get TextureImporter for path: " + path);
    20. }
    It seems like the atlas doesn't have an importer. To circumvent it I tried making a copy by saving the atlas as a png and referencing the png instead. This resulted in a broken atlas.

    2. Using FontEngineEditorUtilities.SetAtlasTextureIsReadable()

    FontEngineEditorUtilities is an internal class, yet somehow it's being accessed from TMPro_FontAssetCreatorWindow. I have no clue how it's able to access it as it's not in the same namespace.

    If anyone knows a way to either use these 2 options or a different option to set isReadable in the atlas to true, any insights will be greatly appreciated!
     
  2. koen_unity718

    koen_unity718

    Joined:
    Feb 5, 2024
    Posts:
    2
    I managed to generate the atlas as a png with readable set to true, and reference it correctly in the font + material.
    I got the atlas population mode set to dynamic but newly inserted characters are still not showing up in-game.
    If I set readable to false on the png I will get an error about it not being readable, so it is using the png
     
    Last edited: Mar 12, 2024