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
  3. Dismiss Notice

TextMesh Pro What causes text to be rendered as blocks instead of letters

Discussion in 'UGUI & TextMesh Pro' started by adbourdages, Sep 13, 2018.

  1. adbourdages

    adbourdages

    Joined:
    Jul 8, 2012
    Posts:
    75
    Hello,

    I have been using TMPro for year and from to time the game will start but all the text is shown with blocks instead of letters. Next game start, no problem it runs fine.

    What is causing it and how can I mitigate it?

    - The problem is happening from Unity 5.4 to 2018 - and a range of version of TMPro over the years.
    - I've attached an image of what it looks like (no from my game, but it looks exactly like that). The blocks look like they are the size of the letters.
    - It works 99.9% of game launches but sometimes: white blocks (all on the same device without reinstallation of the game)
    - This is using the Distance Field 16 algo
    - It happens on Android (and chromebooks). I haven't seen that problem on PC/iOS (but that might be due to number of players on each platforms)
    - I'm guessing the blocks are colored white because it is my text color scheme. Probably not relevant.
    - I'm not fudging around with the created font assets
    - But there are some sprite assets in the project

    I'm happy to provide more details as needed but I feel like this is not a new issue. I just can't find guidance on what to do about it.
     

    Attached Files:

  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    There are a few things that can result in this.

    The first is Unity somehow losing reference to the texture of the font atlas. This is an internal Unity issue and not related to TMP. From TMP's perspective, the texture is still valid but it happens to be some empty texture. This can be timing related as resources are being loaded.

    The second is potentially related to non-uniform scaling of the text object or the Scale X and Y located in the debug section of the material inspector being set to a value of 0.

    This is also possible when using texture compression (which should be avoided with font atlas texture).

    The biggest challenge here is being able to reproduce the issue to isolate the cause.
     
    ailuropoda0 likes this.
  3. adbourdages

    adbourdages

    Joined:
    Jul 8, 2012
    Posts:
    75
    Since this problem can happen with the same executable, it kind of rules out the non-uniform scaling and texture compression.

    The code in the game doesn't ever touch the font reference to the atlas so that leaves Unity losing the reference during load time. But I've never really seen that happen to anything other than TMPro. Most other missing references in the scenes would cause pretty serious crashes or at least a few NullException.

    There has been no luck so far getting logs from a player that exhibited the problem however.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    It does look like some loading / timing issue. This loss of reference to the texture (texture ID to be more specific) occurs on the native side and from the managed side, you still have a valid texture. It is simply and temporarily pointing to the wrong texture.

    This behavior has been around for a while and in the past could occur during assembly reload or when switching build platform.

    Most of these issues got fixed over time but I think the underlying root cause remains somewhere as this keep resurfacing in some form or fashion. For instance, changing texture settings like quality can trigger this behavior in Unity 2018.2 and 2018.3. This is being investigated.

    The biggest challenge is getting repro projects to allow us to reliably reproduce the behavior.
     
    Last edited: Sep 14, 2018
  5. TheBladeRPG

    TheBladeRPG

    Joined:
    Aug 17, 2014
    Posts:
    25
    Hello,
    I have exactly the same issue, purple blocks instead of the text.
    I had to move all my projects to a different disk location, since i've done that, no more text, it's a disaster...
    I thought that everything related to a project is supposed to be inside the project folder, isn't it the case ?
    Whatever is the problem, how to fix it please ?
    im using Unity 2017.1.1f1

    also, but this is less important, the problem occurs if i try migrate a project to a recent unity version, all text go purple blocks.
     
    Last edited: Nov 27, 2018
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Purple blocks indicates missing shaders or materials. I would suggest creating an empty project at the new project / file location and then importing TextMesh Pro to see if you get the same behavior. Let me know if everything works as expected with the new project.

    In terms of migrating to a new version of Unity, for Unity 2018 and up, you will need to get the new version via the package manager. The migration / upgrade process is covered in the following post. Be sure to review the updated notes at the bottom of the first post.
     
  7. TheBladeRPG

    TheBladeRPG

    Joined:
    Aug 17, 2014
    Posts:
    25
    Hello Stephan_B, thank you for the feedback.

    Creating new projects with TextMesh works well. Moving the projects to another location works well too, runing them from a different user session works well too. (im testing with Unity 2017.1.1f1)

    So this problem of purple blocks is only happening to my old project.

    In my case i just noticed that unity was throwing the following errors in different cases :

    case 1 - restored project to it original location, but open it from a different session user
    could not access c:\ProgramData\Unity\Unity_lic.??? (sorry im writing this from my memory i forgot the exact terms)

    case 2 - copied the whole project folder to another disk and open it from a different session user
    Shader error in 'TextMeshPro/Distance Field': failed to open source file: 'TMPro_Properties.cginc' at line 126 (on d3d11)
    Compiling Vertex program
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA UNITY_LIGHT_PROBE_PROXY_VOLUME

    I totaly ignore why is trying to access ProgramData regarding to the project, i never did any setting in this way.

    So i decided to test something, i run unity as administrator

    case 1 - restored project to it original location, but open it from a different session user
    this fixed the TextMesh problem, text is back in the correct color, but now there are shader issues on the whole scenes in the editor, when open scene it look good for 2 seconds and then it look like it has been "iced" or "frozen with cold"

    case 2 - copied the whole project folder to another disk and open it from a different session user
    Shader error in 'TextMeshPro/Distance Field': failed to open source file: 'TMPro_Properties.cginc' at line 126 (on d3d11)
    Compiling Vertex program
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA UNITY_LIGHT_PROBE_PROXY_VOLUME
    (so case 2 remain unchanged, project is broken)

    - so now im very worried because this means i cannot move my projects for the moment
    - why do i need to run as administrator ?
    - why is there are data in c:\ProgramData regarding to the projects?

    how to fix this mess ?
    thank you for helping

    Edit:
    I tried to re-import TextMesh Pro, very bad idea, it broke the project, all texts have vanished, all references to text object and scripts are broken, there are around 300 references to fix, so i wont do that.
    I hope that there is a different solution
     
    Last edited: Nov 27, 2018
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    What version of TextMesh Pro are you using?

    Are you using the free / DLL only version from the Asset Store or the original source code version purchased from that Asset Store?

    When re-importing TextMesh Pro, you have to make sure you stick to the same version in terms of the DLL-only or the source code version. You cannot go back and forth between those.
     
  9. sunwangshu

    sunwangshu

    Joined:
    Mar 2, 2017
    Posts:
    22
    I have seen a similar issue, and the way I fixed it was by checking the "TexCoord1" on Canvas -> "Additional Render Channels".

    Hope it helps : )
     

    Attached Files:

    PNUMIA-Rob likes this.
  10. manuelgoellnitz

    manuelgoellnitz

    Joined:
    Feb 15, 2017
    Posts:
    398
    I had the same problem. After reading this thread i discovered, that the z-Value of the RectTransform Scale-Value was 0.
     
  11. watchagames

    watchagames

    Joined:
    Oct 1, 2017
    Posts:
    26
    Hi, had the same problem.
    In the end re-importing the essentials and regenerating the font solved the "issue"
    (using TMP Package 2.1.0 preview 4)


    upload_2020-2-6_20-43-56.png
     
    ewHurtado, verycooldad and Tartopom29 like this.
  12. YoungXi

    YoungXi

    Joined:
    Jun 5, 2013
    Posts:
    63
    Having the same issue here, when using Dotween to animate TextMeshPro's parent transform from scale (1, 0, 1) to (1, 1, 1). TextMeshPro is rendered as blocks during a short period of time.
     
    devclv and JonBFS like this.
  13. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Issue is related to SDF Scaling which is caused by the scale being zero which will cause the white blocks.

    Instead of scaling from (1, 0, 1) scale from (1, 0.0001f, 1) and the issue should go away.
     
    Ony, JonBFS and YoungXi like this.
  14. Vely-Digital

    Vely-Digital

    Joined:
    Jun 24, 2018
    Posts:
    4
    I had the same issue and this was an easy fix!
     
  15. nati8oy

    nati8oy

    Joined:
    Dec 29, 2013
    Posts:
    1
    This worked for me too! Using 2019.3.0f6
     
  16. Booyaka_619

    Booyaka_619

    Joined:
    Sep 16, 2019
    Posts:
    2
    This happens to me when changing between virtual cameras.
    The texts are ok in initial camera view, but when changing the virtual camera all texts shown as blocks.
     
  17. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Can you provide me with a sample scene where I can reproduce this behavior with a virtual camera?
     
  18. bogheorghiu

    bogheorghiu

    Joined:
    Oct 14, 2018
    Posts:
    9
    I had this issue and found a different fix.

    The issue:
    I had just made a custom SDF font asset and placed in my scene as part of a UI TMP object.
    When making the text small enough and/or zooming out enough in the Scene View, each letter was progressively being replaced with a white square. By progressively I mean that the square was grey at first, and gradually became fully white as the letter got smaller on the screen (either because of actual size or because of zooming out). In Game Mode, the grey squares appeared even after I had solved the problem in the Scene View.

    The solution:
    This being a font asset that I had made, I simply re-created the asset from the original font, decreased the resolution of the atlas (I had gone for maximum) to the recommended 2048x2048, and increased the padding. I did these one after the other, not at the same time, and they both helped (the text was visible from a greater distance after changing the atlas resolution, and from virtually any distance after increasing the padding.

    edit: it turns out that the SP/PD ratio should be around 10%, as the Unity Learn page suggests (1/10 ratio between padding and font size). since I left sampling size set to auto, I guess the atlas resolution is what determines the font size. so I just have to get the padding right depending on the atlas resolution.

    Questions:
    1. As I'm new to TMP, I don't fully understand what those settings mean beside the explanations on the Unity learn page, for which I'm thankful. It says there that 2048 is recommended for mobile. Does that mean that higher resolutions are recommended for PC/Mac? Also, why is the default set to 512?
    2. Why is it called SP/PD ratio and not the other way around? I suppose the Padding D(istance?) is 10% of the Sampling Point (Size) - my attempt at guessing what SP and PD stand for, so it should be PD/SP ratio, right?
    Thank you.
     
    Last edited: Jan 13, 2021
  19. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    The sampling point size determines the accuracy of the representation of the glyphs in our atlas texture. The larger the sampling point size, the more space these glyphs will take in a texture where depending on how many glyphs we are trying to include in our atlas will require using a larger texture.

    The padding is the space between our glyphs in the texture. The larger the padding, the more space each glyph will occupy thus also eventually forcing us to increase texture size. This padding also determines the spread of the Signed Distance Field.

    The Sampling Point Size to Padding ratio determines the effective range of material properties such as Dilation, Outline Width, Underlay Offset, etc. Texture size does not factor into this effective range. It is purely driven by the Sampling Point Size to Padding ratio.

    For example: Let's say we have a primary static font asset with sampling point size of 100 and padding of 10 for a ratio of 10% where as a result of the numbers of glyphs we need to include resulted in an atlas texture of 1024 x 1024. This primary static font asset contains all the known characters used in the project for our Latin languages (again for example). Now in order to handle user input, we assign as fallback to this primary font asset a dynamic font asset with sampling point size of 60 and padding of 6 for the same 10% ratio but use an atlas size of 512 x 512 with multi atlas texture enabled. As a result of these two font assets having the same sampling point size to padding ratio, the visual appearance of our material presets will be consistent between our primary and any of its fallbacks. The fact that our atlas textures are of different size does not matter.

    When creating a font asset, you have to think about how it will be used. Will this font asset be used to mostly display small plain white text where a smaller sampling point size can be used as well as smaller padding / sampling point size to padding ratio or will it be used to display large titles where you expect to use a thick outline and shadow with glow which would require using a larger sampling point and padding / larger sampling point size to padding ratio. You basically have to balance all of the above.

    For Latin characters, a sampling point size of 72 to 90 is usually good and padding value that would result in Sampling Point Size to Padding Ratio of 10% which provides for a good effective range on those material properties. As for the texture size, I always start with 1024 x 1024 but it is ultimately driven by the number of glyphs we need to include at a sampling point size and padding that works for your needs.

    Now in terms of atlas size, 2048 x 2048 is the maximum size that should be used as many mobile devices do not support textures larger than 2048 x 2048.

    On mobile devices, texture size affects texture sampling performance. Reading from a smaller texture is more efficient than reading from a larger texture. Depending on the device, this performance delta can be marginal.

    Again, we have we have to balance the above against the need to include a certain # of many glyphs at a sampling quality and sampling point size to padding ratio that works for our needs combined with the using larger textures will potentially increase build size and memory overhead. On the flip side, using more smaller texture will increase the # of draw calls.

    On Desktop platforms, 2048 x 2048 is totally fine whereas in mobile devices 1024 x 1024 is usually best. Most of the time and on most mobile devices, it is more efficient to use a few 1024 x 1024 and a few extra draw calls then to use a larger 2048 x 2048 resulting in higher memory overhead. Again, this is subject to the targeted devices so please do test all of this to figure out what ultimately works best for you.

    In terms of the use of static and dynamic font assets, I recommend that you use static font assets that contains all the known characters used in the project at build time for any given language or groups of languages. This will ensure that all the known text is already baked in those font assets and textures and provide the best overall performance at runtime. Then for the unknown text which typically comes from user input, I recommend assigning a dynamic font asset with multi atlas texture enabled to this primary font asset. Multi atlas texture enables a dynamic font asset to create new atlas textures as needed which makes them capable of handling every single character contained in their source font file at the cost of an extra draw call per atlas texture used.

    It is important to understand that dynamic font assets have the atlas texture set to size 0 when first created, Reset via the context menu or when the Clear Dynamic Data on build is enabled. When the first glyph is added to the atlas texture, the texture is then resize to the defined size in the Generation Settings. Changes to dynamic font assets are persistent in the Editor but not in builds. This means that if this dynamic font asset was reset before the build, its atlas texture will be of size 0 and not contribute to the build size. It also means that any changes to this font asset at runtime, will only persist for that play session and will reset back to its default ship state for each play session. This ensures you don't have to worry about glyphs being added over the life of the application but just for a play session.

    I realize this is a lot of information to digest. I have made similar posts in the past that contain this information but the above is all the major important stuff.

    In addition, the following two videos also provide similar information with the addition of how to handle CJK / Localization and recommended workflows to using static and dynamic font assets



     
  20. bogheorghiu

    bogheorghiu

    Joined:
    Oct 14, 2018
    Posts:
    9
    @Stephan_B wow, thanks a lot for the text and especially the videos. now it's really clear. it would be great if this kind of detailed, clear explanation was readily available in the Unity Documentation or on Unity Learn - not just for TextMeshPro but for many other newer features (and some older ones too).

    edit, slightly off-topic:
    what I'm currently having trouble with are the overflow modes.
    I'm also curious (this seems solved, see links below) if there's a way to get word wrapping data from the text box via code at runtime, such as where the line breaks (caused by word wrapping) are, the number of lines the text is formatted into etc.
    I found these, and it seems to be what I need. will read through it.
    https://forum.unity.com/threads/textmeshpro-maxvisiblelines.533449/
    http://digitalnativestudios.com/forum/index.php?topic=1113.msg8528#msg8528

    edit 2:
    I had posted a link to something I had written in another thread about ScrollRect overflow mode, but in the meantime I realized that it was completely wrong so I deleted it.
     
    Last edited: Jan 15, 2021
  21. altair2020

    altair2020

    Joined:
    Mar 6, 2011
    Posts:
    49
    Guys, im using unity 2021.3.0f1 and the fonts are still corrupt...
     
  22. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    What do you mean by corrupted?

    What version of the TMP package are you using?

    If you are using the latest release which is version 3.2.0-pre.3 for Unity 2020.3 or newer, be sure to re-import the TMP Essential Resources.
     
  23. aburdieieva

    aburdieieva

    Joined:
    Sep 30, 2022
    Posts:
    1
    Hi everyone! I had the same problem with project for Oculus 2 after updating Text Mesh Pro to newer version.
    After I changed font shader to TextMeshPro/Mobile/DistaceField instead of TextMeshPro/DistanceField - it worked for me.
     
  24. Euromancer

    Euromancer

    Joined:
    Aug 21, 2017
    Posts:
    13
    I was using a World Space canvas with a hierarchy of rect transforms scaled in different ways and the TMP text field in the bottom of the hierarchy.

    The TMP text showed properly in most scenes but in one scene where the original canvas was scaled to a bit smaller size, the text became blocky.

    It was solved by halving the width and height of the rect transform of of the game object holding the TMP Text and instead doubling the scale.

    Hopefully that helps someone as well.
     
  25. justin_at_melcher

    justin_at_melcher

    Joined:
    Dec 10, 2021
    Posts:
    2
    If anyone is still having this issue - I was also tweening from a 0 scale on my TMP object's Parent, but this fix didn't change anything for me. Buried in the "Extra Settings" on the TMP asset, there is an "Is Scale Static" bool that when turned off fixed the problem for me.

    The tooltip says "Controls whether a text object will be excluded from the InternalUpdate callback to handle scale changes of the text object or its parent(s)" which makes sense that this would fix it.
     
    unity_oQhhbvnz7Z9uJw likes this.
  26. Knarhoi

    Knarhoi

    Joined:
    Apr 11, 2015
    Posts:
    10
    To anyone it might help.
    I was fortunate to have two projects - an old and a new one. So I could make comparisons.

    My issue
    Using the same code for creating text objects in-game, I received only white squares in the new game, for these text-objects only.

    I noticed that the old game had no atlases attached to its fonts whatsoever. The new project did. And sure enough, as I changed material from 'Regular' to 'Material' all the text looked fine.

    (Now the real question is: how is the old game still working? xD )
    upload_2024-4-14_23-48-33.png