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 error stops from making build

Discussion in 'UGUI & TextMesh Pro' started by jens_unity858, Sep 6, 2021.

  1. jens_unity858

    jens_unity858

    Joined:
    Nov 26, 2019
    Posts:
    17
    Hi,

    I get this error when I try to make a build
    "UnassignedReferenceException: The variable material of TMP_FontAsset has not been assigned.
    You probably need to assign the material variable of the TMP_FontAsset script in the inspector."

    As far as I can tell I already have assigned a material. in "Material Present" one material is assigned and the font also have a material.

    I am using HDRP.
     
    SparkesRS likes this.
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    This is the result of incorrect serialization of font assets when SRP (URP & HDRP) is used.

    Long story short, the font asset data correctly gets serialized but the additional atlas textures do not so we end up with glyphs referencing atlas index 1 for instance where atlas texture at index 1 does not exist.

    Font assets that are in this state can be reset via the context menu reset option.

    This serialization issue was addressed in the latest preview releases of the TMP package. The latest preview for 2019.4 is version 2.2.0-preview.1 and version 3.2.0-pre.1 for Unity 2020.x or newer.
     
  3. jens_unity858

    jens_unity858

    Joined:
    Nov 26, 2019
    Posts:
    17
    Hi again,

    Thanks for the reply. I tried to update to the preview version but that gave me a lot of errors:
    upload_2021-9-9_11-34-20.png
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    The above issues are related to using an older version of 2019.4 where some of those new FontEngine features were not available yet. There should be compiler conditional to deal with those so not sure why these errors are showing up but I would recommend updating to the latest 2019.4 which is 2019.4.30f1.
     
  5. jens_unity858

    jens_unity858

    Joined:
    Nov 26, 2019
    Posts:
    17
    Hi,

    Thanks for the reply. I updated to the latest version of 2019.4.30f1 but I still get the exact same error:

    "UnassignedReferenceException: The variable m_Material of TMP_FontAsset has not been assigned.
    You probably need to assign the m_Material variable of the TMP_FontAsset script in the inspector.
    TMPro.TMP_FontAsset.ReadFontAssetDefinition () (at Library/PackageCache/com.unity.textmeshpro@2.2.0-preview.1/Scripts/Runtime/TMP_FontAsset.cs:714)
    TMPro.TMP_FontAsset.OnValidate () (at Library/PackageCache/com.unity.textmeshpro@2.2.0-preview.1/Scripts/Runtime/TMP_FontAsset.cs:664)
    UnityEditor.AssetDatabase:LoadAssetAtPath(String)
    TMPro.TMP_PreBuildProcessor:OnPreprocessBuild(BuildReport) (at Library/PackageCache/com.unity.textmeshpro@2.2.0-preview.1/Scripts/Editor/TMP_PreBuildProcessor.cs:21)
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()"

    Anything else I should do after updating?
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Can you post a screenshot of the font asset inspector of the font asset giving this error?

    Make sure we can see the Font Atlas and Font Material assigned in the Atlas & Material section of this font asset.
     
  7. jens_unity858

    jens_unity858

    Joined:
    Nov 26, 2019
    Posts:
    17
    Hi again,

    Here you go:
    upload_2021-9-14_7-30-19.png

    upload_2021-9-14_7-30-50.png
     
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Not sure how the font asset might have lost reference to its default material but here is how we can fix that.

    Select the font asset giving this error.

    Switch the inspector to Debug mode as seen below

    upload_2021-9-14_0-45-47.png

    Take a look at the Material property to see if anything is assigned there. If nothing is assigned, we will need to manually re-assign the default material to this property.

    Select your font asset in the project and expand it to see its default material and atlas texture.

    upload_2021-9-14_0-41-49.png

    Now that you know its default material name, either select it in the Material property list or drag-and-drop it to this material property. This should resolve that issue.
     
    nshawkins-u1 and Evgeno like this.
  9. jens_unity858

    jens_unity858

    Joined:
    Nov 26, 2019
    Posts:
    17
    Hi,

    Thanks again. The error still remains. The font had the material in the debug inspection.

    Is there a way to pinpoint which font and/or which component the error comes from?

    I noticed I had one strange "TMP Sub Mesh UI" That might create the error:

    upload_2021-9-14_12-34-7.png
     
  10. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Normally clicking on the error message, should ping the font asset in question. If it does not, go through all of your font assets as one of them is likely missing its Material assignments.

    If all of the above fails, you could submit a bug report with project so that I can take a closer look. If you end up submitting a bug report, please provide me with the Case # once you have it.
     
  11. jens_unity858

    jens_unity858

    Joined:
    Nov 26, 2019
    Posts:
    17
    Hi Again,

    Thanks for the reply! I finally found 2 fonts (that was not in any scene) in the asset folder that did not have any materials and that seemed to remove the error

    However, I still cannot build the game. I get these errors:

    upload_2021-9-16_13-43-10.png
     
  12. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Re-import the shaders contained in the TMP Essential Resources.

    I have seen this TMPro_Properties.cginc error a few times before which appears to be an import issue.

    It is possible both missing material issue and this .cginc issue are both related to some import process that went wrong.
     
  13. jens_unity858

    jens_unity858

    Joined:
    Nov 26, 2019
    Posts:
    17
    Sorry for the late reply i had some other issues with the project. Reimport did not fix the issue.

    I think this is the shader that creates the error but for some reason that is the only shader I have that works with the font.

    Could this shader create the errors?
     

    Attached Files:

  14. jens_unity858

    jens_unity858

    Joined:
    Nov 26, 2019
    Posts:
    17
    Hi Again,

    Did you see my above reply?
     
  15. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    The above shader expects the "TMPro_Properties.cginc" to be located in the same folder as the shader itself. Make sure this is the case. The shader also only appears to be changing the ZTest value instead of using the variable [unity_GUIZTestMode]

    The above shader (if still needed) will need to be revised as well as the UV Layout of the text geometry has changed. So this shader can indeed end up producing errors.

    I would suggest creating a new shader based on the "TMP_SDF-Mobile" which includes the latest changes and then modifying the ZTest to your needs.
     
  16. Hafiz1003

    Hafiz1003

    Joined:
    Dec 15, 2021
    Posts:
    2
    Hi Again, @UnityTechnologies please help

    Thanks for the reply!!
     

    Attached Files:

  17. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    You need to update the TMP Essential Resources as per the Upgrade Note in Package Manager as seen below.

    upload_2022-1-7_21-18-48.png

    This will resolve the issue related to Vector4 / Vector2.

    In terms of the other error about about the material variable, that could be indirectly related to the other error but it is hard to tell without more information.

    I would suggest first updating the TMP Essential Resources and then see if the other message persists. If it does, we can then take a closer look at that prefab to see what the issue might be.
     
  18. Hafiz1003

    Hafiz1003

    Joined:
    Dec 15, 2021
    Posts:
    2
    Hi Again, @UnityTechnologies please help
    I have a button restart,save and resume but it doesn't work

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.SceneManagement;
    6.  
    7. public class HUDManager : MonoBehaviour
    8. {
    9.     public Image currentEnergy;
    10.  
    11.     private GameObject player;
    12.     private float energy = 200;
    13.     private float maxEnergy = 200;
    14.     private float kecepatan;
    15.     private float kecepatanLari;
    16.     private float kecepatanJalan;
    17.     private float kecepatanLari1;
    18.     private float kecepatanJalan1;
    19.     private float input_x;
    20.     private float input_z;
    21.     public Text clockText;
    22.     [SerializeField] GameObject pauseMenu;
    23.  
    24.     [SerializeField] GameObject GameOverMenu;
    25.     [SerializeField] GameObject IsInformation;
    26.     string info;
    27.  
    28.     public static bool GameIsPaused = false;
    29.     public Player playerInstance;
    30.  
    31.     private float darah;
    32.     private float maxDarah = 100f;
    33.     public Image currentDarah;
    34.  
    35.     // Start is called before the first frame update
    36.     void Start()
    37.     {
    38.         player = GameObject.Find("Player");
    39.         kecepatanLari = player.GetComponent<PergerakaPlayer>().speed_lari;
    40.         kecepatanJalan = player.GetComponent<PergerakaPlayer>().speed_jalan;
    41.         kecepatanLari1 = player.GetComponent<PergerakaPlayer>().speed_lari;
    42.         kecepatanJalan1 = player.GetComponent<PergerakaPlayer>().speed_jalan;
    43.         GameIsPaused = false;
    44.         Time.timeScale = 1f;
    45.        
    46.     }
    47.  
    48.     // Update is called once per frame
    49.     void Update()
    50.     {
    51.         kecepatan = player.GetComponent<PergerakaPlayer>().kecepatan;
    52.         input_x = player.GetComponent<PergerakaPlayer>().x;
    53.         input_z = player.GetComponent<PergerakaPlayer>().z;
    54.         darah = player.GetComponent<SistemDarah>().darah;
    55.         info = player.GetComponent<SistemDarah>().info;
    56.         ShowPauseMenu();
    57.         UpdateDarah();
    58.         EnergyDrain();
    59.         UpdateEnergy();
    60.         UpdateTime();
    61.         gameOver();
    62.  
    63.         Text pesan = IsInformation.GetComponent<Text>();
    64.         pesan.text = info;
    65.      
    66.  
    67.     }
    68.  
    69.     private void EnergyDrain()
    70.     {
    71.  
    72.         if (!HUDManager.GameIsPaused)
    73.         {
    74.             if (kecepatan == kecepatanLari)
    75.             {
    76.                 if (input_x > 0 || input_z > 0)
    77.                 {
    78.                     if (energy > 0)
    79.                     {
    80.                         energy -= 10 * Time.deltaTime;
    81.                     }
    82.                     else
    83.                     {
    84.                         if (energy < maxEnergy)
    85.                         {
    86.                             energy += 15 * Time.deltaTime;
    87.                         }
    88.                     }
    89.                 }
    90.             }
    91.             else if (kecepatan == kecepatanJalan)
    92.             {
    93.                 if (input_x > 0 || input_z > 0)
    94.                 {
    95.                     if (energy > 0)
    96.                     {
    97.                         energy -= 6 * Time.deltaTime;
    98.                     }
    99.                 }
    100.                 else
    101.                 {
    102.                     if (energy < maxEnergy)
    103.                     {
    104.                         energy += 15 * Time.deltaTime;
    105.                     }
    106.                 }
    107.             }
    108.         }
    109.        
    110.  
    111.  
    112.         Debug.Log(energy);
    113.     }
    114.  
    115.     private void UpdateEnergy()
    116.     {
    117.         float ratio = energy / maxEnergy;
    118.         currentEnergy.rectTransform.localScale = new Vector3(ratio, 1, 1);
    119.     }
    120.  
    121.     private void UpdateTime()
    122.     {
    123.         int hours = EnviroSky.instance.GameTime.Hours;
    124.         int minutes = EnviroSky.instance.GameTime.Minutes;
    125.         string gameHours;
    126.         string gameMinutes;
    127.  
    128.         if (hours >= 0 && hours < 10)
    129.         {
    130.             gameHours = "0" + hours.ToString();
    131.         }
    132.         else
    133.         {
    134.             gameHours = hours.ToString();
    135.         }
    136.         if(minutes >= 0 && minutes<10)
    137.         {
    138.             gameMinutes = "0"+ minutes.ToString();
    139.         }
    140.         else
    141.         {
    142.             gameMinutes = minutes.ToString();
    143.         }
    144.  
    145.         clockText.text = gameHours + " : " + gameMinutes;
    146.  
    147.     }
    148.     private void ShowPauseMenu()
    149.     {
    150.         if (Input.GetKeyDown(KeyCode.Escape))
    151.         {
    152.             if (GameIsPaused)
    153.             {
    154.                 Resume();
    155.             }
    156.             else
    157.             {
    158.                 Pause();
    159.             }
    160.         }
    161.     }
    162.     public void Resume()
    163.     {
    164.         pauseMenu.SetActive(false);
    165.         GameIsPaused = false;
    166.         Time.timeScale = 1f;
    167.         Cursor.lockState = CursorLockMode.Locked;
    168.     }
    169.     void Pause()
    170.     {
    171.         pauseMenu.SetActive(true);
    172.         GameIsPaused = true;
    173.         Time.timeScale = 0f;
    174.         Cursor.lockState = CursorLockMode.Confined;
    175.     }
    176.  
    177.     public void SaveGame()
    178.     {
    179.         SaveSystem.SavePlayer(playerInstance);
    180.     }
    181.  
    182.     private void UpdateDarah()
    183.     {
    184.         float ratio = darah / maxDarah;
    185.         currentDarah.rectTransform.localScale = new Vector3(ratio, 1, 1);
    186.     }
    187.     public void gameOver()
    188.     {
    189.         if (darah < 1)
    190.         {
    191.             //player mati
    192.             GameOverMenu.SetActive(true);
    193.             GameIsPaused = true;
    194.             Time.timeScale = 0f;
    195.             Cursor.lockState = CursorLockMode.Confined;
    196.             Cursor.visible = true;
    197.         }
    198.     }
    199.     public void restart()
    200.     {
    201.         //SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    202.         SceneManager.LoadScene("SampleScene");
    203.     }
    204. }
    205.  

    Thanks for the reply!!
    Screenshot (543).png
     

    Attached Files:

  19. fadizant

    fadizant

    Joined:
    Dec 17, 2016
    Posts:
    9
    Hi

    I have the same issue when I use Unity 2023 but I do not face this issue in Unity 2021.

    this error list comes when I try to make TMP_FontAsset using TextMesh pro 3.0.6

    Any help with this issue, please.

    upload_2023-11-8_18-28-21.png
     
  20. KekoApps

    KekoApps

    Joined:
    Jan 28, 2022
    Posts:
    9
    Hello,

    I have the same error. TMPro used to work and then something went wrong. It might have happened around the time I installed Unity 2023.1.19f, but I can't be sure. Anyway, now even the versions that previously could import (such as 2022.2) can't create proper SDF files anymore. They are all small and contain zero chars.

    I've created a new project and used the TMPro sample scene "01- Single Line TextMesh Pro" for test. Then I've tried to create a SDF file from the fonts included with the Examples and Extras. All the produced SDF files were useless and had zero chars.

    TMP font asset error.jpg TMP font asset project.jpg
     
  21. Welfarecheck

    Welfarecheck

    Joined:
    Jun 14, 2020
    Posts:
    120
    Same error here with 0 characters for all imported for 2023.1.2 fonts. It worked and then suddenly broke for all projects including new projects.

    @MelvMay I think this broke at the same time as the animated tiles so it's possible it's related.
     
  22. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,573
    TMP has no relationship with the TilemapRenderer so it won't be related. Looking at the fix the dev produced for the Tilemap, it was related to some "dirty flag" not being set correctly. It was also only a problem in the player AFAIK too.
     
  23. Welfarecheck

    Welfarecheck

    Joined:
    Jun 14, 2020
    Posts:
    120
    Got ya. Appreciate the input and update on the tilemap!
     
    MelvMay likes this.