Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

TextMesh Pro Attempting to add custom tags to the rich text system

Discussion in 'UGUI & TextMesh Pro' started by renardmf, Jul 16, 2018.

  1. renardmf


    Jun 29, 2012

    I am trying to add a custom tag to the rich text system which would allow for more functionality based on a specific tag. I was attempting to add one in the TMP_Text.cs file following along with the other tags in the switch statement found there. But for whatever reason I can't seem to figure out how to hash my tag so that it works the same as the other tag lookups there. I tried using GetSimpleHashCode() function but it seems to give me different results when trying to hash non single character tags. I am also not sure if this is the only step needed to be able to add this new functionality.

    Any help with this would be much appreciated.

  2. Stephan_B


    Unity Technologies

    Feb 26, 2017
    Take a look in the TMP_Text.cs file around line 6151, and uncomment that first Debug.Log line of code. This will have the affect of printing the hashcode of whatever tag you just typed in the text input box.

    For instance <myCustomTag> will produce hashcode 1811234461.

    Note these are case sensitive (for the time being).

    You will need to add the closing part of the tag as well </myCustomTag>

    Then add the functionality similar to how the other tags are implemented.

    Note: The hashcode used in the parsing of the text is slightly different than that of the GetSimpleHashCode() function.
    Last edited: Jul 16, 2018
  3. Ferazel


    Apr 18, 2010
    Sorry for bumping such an old topic, but I'd love a way to add custom tags without having to modify the source of the base TMP so that we can still keep up-to-date on other changes/bugfixes without having to do manual package update code merges. I understand that this support is never going to be code-free. However, if we could template the CharacterInfo struct so we can add our own custom data and have a virtual method to add additional parsing I think that could go a long way to making this feature easier to support.

    I originally was using <link> tag but we now need to stack tags and you can't do that with links.

    EDIT: I decided to modify the source to add the custom tags, but would have loved a less intrusive solution. Something to think about for the future.
    Last edited: Dec 5, 2020
  4. NeatWolf


    Sep 27, 2013
    since we're now using packages, is there now a less intrusive way to do that?

    My intention is to add a UI prefab (which also contains scripts at runtime) right where the custom tag would be.

    Is there a "clean" way to do that now?