Search Unity

TextMesh Pro TextMeshPro not showing the materials on the list

Discussion in 'UGUI & TextMesh Pro' started by free4allgames, Apr 16, 2019.

  1. free4allgames

    free4allgames

    Joined:
    Dec 5, 2018
    Posts:
    42
    I have a few materials for a font, they used to appear on the textmesh pro materials list, but now they are gone, even though the old texts that used them still has them "properly".

    You can see on the assets folder I have some materials:



    On an old Textmesh object on the scene, this is the inspector:



    On the Main settings the Material Preset shows the wrong material, and if I click on it none of the other materials show up.

    If you look on the bottom of the image you can see that it is using another material (the Offers one), which is not what is shown on the materials list...

    Problem is I cannot create new text elements and choose the custom materials anymore...

    A few days ago the issue was different, the materials would show up on the dropdown list, but selecting them didn't change the selection, it would only change after I pressed play.

    Now they don't even show up anymore.

    Using Unity 2018.3.12f1 and Textmeshpro 1.4.0.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The D-DIN SDF font asset shows multiple child atlas textures. What are those other atlas textures?

    Could you please submit a bug report that includes the project for me to look at or perhaps a new project with the relevant scene and assets to allow me to reproduce the behavior to figure this out.
     
  3. free4allgames

    free4allgames

    Joined:
    Dec 5, 2018
    Posts:
    42
    I did not notice this was an issue, I looked at the asset file and apparently it was conflict error with git and somebody resolved it wrongly, let me just check this first...


    Edit: That wasn't it.

    The new atlas textures are created when I choose to update the atlas, it creates and adds a new one to the asset file.

    I'm trying to trim down the project to submit, it's a huge project...
     
    Last edited: Apr 16, 2019
  4. free4allgames

    free4allgames

    Joined:
    Dec 5, 2018
    Posts:
    42
    I submitted a bug report using the editor feature, Case 1146562, it's a project with a single scene showing the text with conflicting material information and the bugged font asset.
     
  5. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I will need to review / figure out why these additional atlas textures are getting created as this should not be happening either.

    Once you have been able to submit the bug report and project. Please provide me with the Case #.
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Thank you. I'll look at it this afternoon.
     
    free4allgames likes this.
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Just got around to looking at the Repro case you provided (Thank you) and the issue is definitely related to having multiple atlas textures as sub assets.

    As it turns out each of your material preset's atlas textures point to the third atlas texture whereas the material of the font asset points to the first. As such, when TMP looks to find materials that use this atlas texture, it doesn't find any using this first atlas texture.

    So the issue is related to the fact you ended up with multiple atlas textures which I have never encountered thus far. New mystery to solve / figure out.

    Can you provide the steps you took to update your font asset?

    I'll try reproducing this multi atlas texture issue tomorrow.

    Notes
    Interestingly enough, there is no easy way to delete sub assets in the Editor.

    Although we could easily create a new font asset to fix this, if your project contained over 1000 text objects and material presets all referencing this font asset, we would end up breaking all these references which would not be cool. I already have (and for unrelated reasons) modified the Reset function on Font Assets to clear out multi atlas textures (this will be in the next release). However, I will also modify the Font Asset Creator to deal with this as well.

    This will enable users to regenerate their font assets and clear out multi atlas textures (Multi atlas texture support is coming in 1.4.2 and 2.0.2) while maintaining whatever references object might have to this asset.

    I do need to check / make sure Material Presets maintain the correct reference to the main atlas texture even when multiple atlas textures are used.

    P.S. In this future release of TMP font assets will be able to have multiple atlas textures which will be created on demand as each atlas texture fills up. I'll create a video of this new feature when ready.
     
  8. free4allgames

    free4allgames

    Joined:
    Dec 5, 2018
    Posts:
    42
    I did some more testing and it's only happening on that asset and on that project.

    The steps:
    Click the font asset, and on the inspector click on "Update Atlas Texture".

    It will open the "Font Asset Creator".

    Select a different character set, click on "Generate Font Atlas" then Save. It will add a new atlas to that font asset.

    I created a new project and a new font asset and did the same thing, the error did not happen.



    edit: I downgraded the tmp version to 1.3.0 and when I click to generate font atlas unity crashes...
     
  9. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Since font assets get converted to a newer format in 1.4.0, going to back to 1.3.0 with an upgraded font asset is likely to misbehave. I would suggest remaining on 1.4.0.

    I will take a look at this particular font asset to see if I can figure out why it is behaving this way in 1.4.0 and why only this one is.
     
  10. free4allgames

    free4allgames

    Joined:
    Dec 5, 2018
    Posts:
    42
    Well it might not be an issue if it doesn't happen anymore.

    The project is 6 months old, I update Unity constantly, the asset was probably generated on TMP 1.3.0 or prior and also upgraded constantly...

    What would help me here is a way to fix the current asset, but since it doesn't seem to be an easy fix I guess I'll probably just create a new one and replace everywhere, it will be safer.
     
  11. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I am looking at the project you provided right now to figure out why this is happening in the first place. I'll post back as soon as I have more information.
     
    free4allgames likes this.
  12. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    With the next release of TextMesh Pro which will be version 1.4.1 (Unity 2018.3) and 2.0.1 (Unity 2019.1), it will be possible to remove the sub assets / erroneous atlas textures and to manually re-assign the appropriate atlas texture to the Material Presets.

    Furthermore, with the release of TMP version 1.4.2 and 2.0.2 where multi atlas texture will be added as a new feature, the Font Asset Creator will also be updated to correctly handle multiple atlas textures.
     
    free4allgames likes this.
  13. free4allgames

    free4allgames

    Joined:
    Dec 5, 2018
    Posts:
    42
    Thanks, I'll wait for it before doing anything else with my broken asset.

    In regards to how the asset got broken, I can't tell how it happened, but I remembered now that I use a script to curve the text, maybe something on it broke the asset at some point? I don't know, anyway, here's a copy of the script, nothing else on the project messes with the TMP.

    It's a copy of a script I found on the forums, and I modified it a bit to avoid some GC.


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using TMPro;
    4.  
    5. public class CurvedTextMeshPro : MonoBehaviour
    6. {
    7.     private TMP_Text m_TextComponent;
    8.  
    9.     public AnimationCurve VertexCurve;
    10.     public float AngleMultiplier = 1.0f;
    11.     public float SpeedMultiplier = 1.0f;
    12.     public float CurveScale = 30.0f;
    13.  
    14.     private void Awake()
    15.     {
    16.         this.m_TextComponent = this.gameObject.GetComponent<TMP_Text>();
    17.     }
    18.  
    19.     private void Start()
    20.     {
    21.         this.StartCoroutine(this.WarpText());
    22.     }
    23.  
    24.     private AnimationCurve CopyAnimationCurve(AnimationCurve curve)
    25.     {
    26.         AnimationCurve newCurve = new AnimationCurve
    27.         {
    28.             keys = curve.keys
    29.         };
    30.  
    31.         return newCurve;
    32.     }
    33.  
    34.     /// <summary>
    35.     ///  Method to curve text along a Unity animation curve.
    36.     /// </summary>
    37.     /// <param name="textComponent"></param>
    38.     /// <returns></returns>
    39.     IEnumerator WarpText()
    40.     {
    41.         yield return new WaitForEndOfFrame();
    42.         this.VertexCurve.preWrapMode = WrapMode.Clamp;
    43.         this.VertexCurve.postWrapMode = WrapMode.Clamp;
    44.  
    45.         Vector3[] vertices;
    46.         Matrix4x4 matrix;
    47.  
    48.         this.m_TextComponent.havePropertiesChanged = true; // Need to force the TextMeshPro Object to be updated.
    49.         this.CurveScale *= 10;
    50.         float old_CurveScale = this.CurveScale;
    51.  
    52.         while (true)
    53.         {
    54.  
    55.             if (!this.m_TextComponent.havePropertiesChanged && old_CurveScale == this.CurveScale)
    56.             {
    57.                 yield return null;
    58.                 continue;
    59.             }
    60.  
    61.             old_CurveScale = this.CurveScale;
    62.  
    63.             this.m_TextComponent.ForceMeshUpdate(); // Generate the mesh and populate the textInfo with data we can use and manipulate.
    64.  
    65.             TMP_TextInfo textInfo = this.m_TextComponent.textInfo;
    66.             int characterCount = textInfo.characterCount;
    67.  
    68.             if (characterCount == 0)
    69.             {
    70.                 continue;
    71.             }
    72.            
    73.             float boundsMinX = this.m_TextComponent.bounds.min.x;
    74.             float boundsMaxX = this.m_TextComponent.bounds.max.x;
    75.            
    76.             for (int i = 0; i < characterCount; i++)
    77.             {
    78.                 if (!textInfo.characterInfo[i].isVisible)
    79.                 {
    80.                     continue;
    81.                 }
    82.  
    83.                 int vertexIndex = textInfo.characterInfo[i].vertexIndex;
    84.  
    85.                 // Get the index of the mesh used by this character.
    86.                 int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;
    87.  
    88.                 vertices = textInfo.meshInfo[materialIndex].vertices;
    89.  
    90.                 // Compute the baseline mid point for each character
    91.                 Vector3 offsetToMidBaseline = new Vector2((vertices[vertexIndex + 0].x + vertices[vertexIndex + 2].x) / 2, textInfo.characterInfo[i].baseLine);
    92.  
    93.                 // Apply offset to adjust our pivot point.
    94.                 vertices[vertexIndex + 0] += -offsetToMidBaseline;
    95.                 vertices[vertexIndex + 1] += -offsetToMidBaseline;
    96.                 vertices[vertexIndex + 2] += -offsetToMidBaseline;
    97.                 vertices[vertexIndex + 3] += -offsetToMidBaseline;
    98.  
    99.                 // Compute the angle of rotation for each character based on the animation curve
    100.                 float x0 = (offsetToMidBaseline.x - boundsMinX) / (boundsMaxX - boundsMinX); // Character's position relative to the bounds of the mesh.
    101.                 float x1 = x0 + 0.0001f;
    102.                 float y0 = this.VertexCurve.Evaluate(x0) * this.CurveScale;
    103.                 float y1 = this.VertexCurve.Evaluate(x1) * this.CurveScale;
    104.  
    105.                 Vector3 horizontal = new Vector3(1, 0, 0);
    106.                 Vector3 tangent = new Vector3(x1 * (boundsMaxX - boundsMinX) + boundsMinX, y1) - new Vector3(offsetToMidBaseline.x, y0);
    107.  
    108.                 float dot = Mathf.Acos(Vector3.Dot(horizontal, tangent.normalized)) * 57.2957795f;
    109.                 Vector3 cross = Vector3.Cross(horizontal, tangent);
    110.                 float angle = cross.z > 0 ? dot : 360 - dot;
    111.  
    112.                 matrix = Matrix4x4.TRS(new Vector3(0, y0, 0), Quaternion.Euler(0, 0, angle), Vector3.one);
    113.                
    114.                 vertices[vertexIndex + 0] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 0]);
    115.                 vertices[vertexIndex + 1] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 1]);
    116.                 vertices[vertexIndex + 2] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 2]);
    117.                 vertices[vertexIndex + 3] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 3]);
    118.  
    119.                 vertices[vertexIndex + 0] += offsetToMidBaseline;
    120.                 vertices[vertexIndex + 1] += offsetToMidBaseline;
    121.                 vertices[vertexIndex + 2] += offsetToMidBaseline;
    122.                 vertices[vertexIndex + 3] += offsetToMidBaseline;
    123.             }
    124.  
    125.             // Upload the mesh with the revised information
    126.             this.m_TextComponent.UpdateVertexData();
    127.  
    128.             yield return new WaitForSeconds(0.025f);
    129.         }
    130.     }
    131. }
     
  14. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    That script should not have affected any of this. It has to be something related to the Font Asset Creator or maybe. At any rate this won't be an issue going forward anyway.