Search Unity

How to hide custom Text Tags from TextMeshPro Text?

Discussion in 'Scripting' started by Rukas90, May 26, 2019.

  1. Rukas90

    Rukas90

    Joined:
    Sep 20, 2015
    Posts:
    120
    Hello everyone,
    I am trying to figure it out on how to hide all rich text tags from the TextMeshPro text.

    If I put for example already existing tags, such as <size=25>SomeText</size> this tag is hidden, but if I place a custom tag, for example <CustomTag>SomeText</CustomTag> this tag is visible and not removed.
    I want to put these custom tags as text markers.

    Is there a way to make all tags invisible? So all characters that start with < and end with >?

    Thank you
     
  2. Vaitaliy

    Vaitaliy

    Joined:
    Jan 10, 2019
    Posts:
    1
    Have you solved this issue?
     
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    6,866
    Strip the custom tags from the string before assigning it to the TextMeshPro?
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    4,970
    So I'll first start out by saying, this may not be the right way. However, it worked for me, so I stuck with it. TMP does give you access to the source code, but in order to modify it per project, you have to copy it over to the project package folder and remove the version code part of the folder name. Then you need to remove the read only so you can modify a file.

    Then, you can open up TMP_Text.cs.

    Within that file, you'll can search for the default tags that TMP uses (like </sup>)
    Then you can insert your own tags if you want here.

    upload_2019-10-9_10-24-18.png

    Here I have an h tag and a /h tag. They don't do anything in this code because I just need the tags hidden, but they are used for other purposes behind the scenes in my own code.

    The hard part may be figuring out the number that goes with your tag, depending on how complex your tag is.

    (and I know OP was back in May, so hopefully they found a solution, but posting this in case it can help others)
     
unityunity