Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

TextMesh Pro Unwanted SubMesh text persistence

Discussion in 'UGUI & TextMesh Pro' started by ahoffmann, Jan 8, 2019.

  1. ahoffmann

    ahoffmann

    Joined:
    Dec 10, 2018
    Posts:
    8
    I am using fallback fonts for multi-language support. When I set an object's text such that a fallback font is used, a TMP_SubMeshUI object is created. When I change the text at runtime to characters that use only the main font, the old text in the SubMesh remains. Is there a way I can clear the submesh text so only the new text remains, using TextMesh Pro APIs? Or is there another way I should be switching an object's text back and forth between different languages/fonts?
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    There is a cost in creating these sub mesh objects but once they are created, there isn't really any cost in having them be dormant. Ie. it would be most costly to delete them then to leave them be or even change their active state.

    Down the road, I would like to do away with the need for sub mesh object completely but we are not there yet.
     
  3. ahoffmann

    ahoffmann

    Joined:
    Dec 10, 2018
    Posts:
    8
    I'm not concerned with the cost of them existing. When changing the text from a fallback character set to a primary character set as described above, the new text and old text are displayed on top of each other (see attached image).
     

    Attached Files:

    • tmp3.PNG
      tmp3.PNG
      File size:
      29.1 KB
      Views:
      793
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Can you provide me with the steps or a simple repro / scene that I could use to reproduce this?
     
  5. ahoffmann

    ahoffmann

    Joined:
    Dec 10, 2018
    Posts:
    8
    Looks like it is caused by a curved UI system I am using. I will follow up with it's author, but if you could still provide some insight it would be appreciated.
    What functions are supposed to run to clear / hide the sub-mesh text in the above situation?
     
  6. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    That is managed by the parent text object. As the text changes, it is responsible for clearing the submesh geometry.

    The Curved UI author has always been pretty responsive so I am pretty sure this is something they'll be able to address.
     
  7. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    662
    Hey @Stephan_B

    This seems related so posting here. I've built a tool for previewing our game in the different languages we support. If I switch to a language that requires a font fallback, it creates sub meshes as expected. But then those sub mesh objects hang around after switching to other languages.

    Is there a convenient way at edit time to 'clean up' sub meshes that were created when switching to a different font asset if the current font asset doesn't require them? Not worried about runtime, but in the editor it would be very welcome.

    Thanks!
     
  8. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    I did make a change where sub objects are no longer serialized.

    I thought I had added special handling (in my dev version) to clean up unused sub mesh objects in the Editor but perhaps I was dreaming. Nonetheless, that is something that I could add in the next release.
     
  9. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    662
    Thanks for the reply Stephan - It must be insane having to answer everyone's questions on here!

    When you say "no longer serialized" - in what sense? The sub objects created in my test are serialized and save with the scene. But is that not what you mean?

    I'm happy to write my own extension to go through and remove them. Is there a way to determine if any are actually being used?

    Thanks!
     
  10. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Those sub objects will no longer be saved with the scene as they are created as needed and were polluting prefabs / source control.

    I am not sure yet how I will handle it as there are a few possibilities. The textInfo.materialCount could be used. This count reflects the number of sub objects used the last time the text was rendered. subObjectCount = materialCount - 1; since one material is used by the primary. There are other internal ways for me to get this info but that might be the simplest.
     
  11. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    662
    I see - you mean you've made a change in a new version to stop them being serialised, but not the current version available in the package manager?

    Using the materialCount sounds good - although when I inspect the TMP_Text object in the debug mode of the inspector, I can see a number of empty sub text objects in the list along with the sub objects that are visible in the scene.

    In one TMP_Text object there are 8 sub mesh objects in the list. 6 of them are empty. textInfo.materialCount = 1.
     
  12. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Correct. This change will be in the next release.

    Most arrays / buffers are allocated in blocks and as such their size will not be representative of the number of valid elements. The textInfo.materialCount or other counts should be used.
     
  13. dyawitz

    dyawitz

    Joined:
    Aug 22, 2017
    Posts:
    5
    Hi, I am having the issue described at the top of this thread where I get submeshes from a fallback font that don't clear out when I change the text - using the latest (I think) CurvedUI and Unity 2019.2.12. Was there any resolution for that original issue? Thanks.
     
  14. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Sub text objects are no longer serialized in the latest preview releases available via the Package Manager. As such sub text objects will be created as needed but not saved with the text object.

    For performance reasons, sub text objects which are no longer persistent between scene reloads or play sessions, will have their geometry cleared when no longer needed but not deleted due to the performance overhead involved. Basically, they will exist in the scene hierarchy but have no performance impact at all.

    When I have time, I plan on adding some code to clean up unused sub text objects in the Editor but not at runtime.
     
  15. dyawitz

    dyawitz

    Joined:
    Aug 22, 2017
    Posts:
    5
    Thanks Stephan - I just tried upgrading the package to the latest preview version and get a flood of errors ending with "Material doesn't have a float or range property '_CullMode'". I found your advice on another forum to try deleting the original package before reinstalling the new one - tried that but I still get the errors. Any suggestions? Thanks.
     
  16. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    See the following Important Note as well as subsequent post to address those shader related issues resulting from the addition of support for Cull Mode which requires updating / importing the updated shaders.

    Preview 3 should be available over the weekend. It will still require updating the shaders but the errors should go away. The changes linked in my referenced post will make those errors go away as well.
     
  17. nindim

    nindim

    Joined:
    Jan 22, 2013
    Posts:
    130
    Hi @Stephan_B ,

    Sorry to resurrect this thread, but it seems relevant to an issue we are seeing at runtime where fonts are not being unloaded.

    As with the OP, we are using a fallback font as part of our multi language support. We are using the latest TMPro (3.0.6) available in Unity 2021.3.17.

    When we change to Arabic for instance, a submesh is created with a reference to the Arabic font material. When returning to English, it would appear that these now unused submesh objects retain references to the Arabic font material which in turn prevents the underlying textures etc from being unloaded.

    Screenshot below shows the issue after switching from Arabic to English.

    Text object now using English font:
    upload_2023-2-13_22-20-15.png

    TMP SubMeshUI [NotoSansArabic-Medium Atlas Material + FUTURA_MD_BT Atlas] - (debug inspector mode)
    upload_2023-2-13_22-19-44.png

    Hopefully you can help.

    Thanks a lot,

    Niall