Search Unity

Question TextMeshPro - Material Preset option not persisting in prefab once material font atlas has changed

Discussion in 'UGUI & TextMesh Pro' started by pikminscience, Jan 10, 2023.

  1. pikminscience

    pikminscience

    Joined:
    Mar 26, 2019
    Posts:
    36
    I'm using the Bitmap Custom Atlas shader and changing the Font Atlas under debug settings of the material.

    If I create a font asset and a few material presets, I can get any chosen material preset to persist within a prefab.

    However, the moment I change any of these materials Font Atlas' - the option won't persist.

    I've been trying to debug the issue to see what it might hit in TMP for this but I'm a bit lost.

    edit: Quick repro -
    • Default LiberationSans SDF font asset - change the Font Atlas to any other texture for now.
    • Create a prefab of a TMP object
    • Create material preset for font asset
    • Set prefabs material preset to new preset, save
    • Close prefab
    • Open prefab - preset didn't persist

    I know editing the font atlas might be a bit of an odd use case, I don't mind doing some custom implementation within TMP to work around it.
     
    Last edited: Jan 10, 2023
  2. pikminscience

    pikminscience

    Joined:
    Mar 26, 2019
    Posts:
    36
    Prefab seems to serialize property change correctly. If I click the prefab once in editor, I can see the correct material preset.

    The moment I open the prefab in the prefab editor, the material preset is lost.

    edit:
    nvm - found it :D

    TMPro_Private
    Code (CSharp):
    1.                 // If font atlas texture doesn't match the assigned material font atlas, switch back to default material specified in the Font Asset.
    2.                 if (m_sharedMaterial == null || m_sharedMaterial.GetTexture(ShaderUtilities.ID_MainTex) == null ||
    3.                     m_fontAsset.atlasTexture.GetInstanceID() !=
    4.                     m_sharedMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID())
    5.                 {
    6.                     if (m_fontAsset.material == null)
    7.                         Debug.LogWarning(
    8.                             "The Font Atlas Texture of the Font Asset " + m_fontAsset.name + " assigned to " +
    9.                             gameObject.name + " is missing.", this);
    10.                     else
    11.                         m_sharedMaterial = m_fontAsset.material;
    12.                 }
     
    Last edited: Jan 10, 2023