Forum rules - please read before posting.

TextMeshPro tags displayed during text scroll

edited October 2018 in Technical Q&A
Hi, the new TextMeshPro support is cool. But I realized when using TMP for dialog text scroll, the Unity rich text tags will be compiled directly without scrolled out (e.g. <color>, <b>, <i>); while the TMP only tags will be partially displayed before the whole tag is scrolled out and compiled (e.g. <link>, <sup>, <sub>). The same applies to SuperTextMesh too. Would there a quick fix in some code so that the scrolling dialog can handle TMP <> tags like the AC [] tags?

I have thought of using SetCustomToken, but it can only be called by [token:ID] which is inconvenient as it is not descriptive, and also I cannot find a way to set custom token that can take parameters.

p.s. I am using Unity 2018.1.4f1 & AC 1.65.0
«1

Comments

  • edited October 2018
    It's never a quick fix - incorporating Unity's "official" ones was a major undertaking, and not something that can be easily added upon.

    I will see if some commonly-used TMP tags can be incorporated, however.

    On the topic of parameterisation: since the [token:X] tag is processed after [param:X], it should be possible to parameterise tokens with:

    [token:[param:X]]

    Edit: I'll add it for a few select tokens, namely those above.
  • edited October 2018
    Thanks Chris. I am thinking whether the script that skips the dialog scroll of the AC [] tags can be modified a bit so that the dialog scroll will skip all the <> tags too. Would it be easier to implement if making the dialog scroll skips any <> tags no matter what text is inside? Even meaningless ones like <bahbah>?

    I have thought of adding a script that reads the last character of the scrolling dialog text field, then when it reads "<", set the scroll speed to super fast until it reads ">". But this doesn't look very neat. Can you point me to the script that handle the AC [] tags for trying to seek a neater solution?
  • Having it work for "any" tag runs the risk of mistaking prose for something to be converted, i.e. "<laughs> OK, then!"

    Like I said, I'll implement the ones you asked for above - but it's more complex than it first appears.  When a tag opens, a closing tag needs to be automatically added on until the closing tag in the original text itself appears, i.e.:

    <b>B</b>
    <b>Bo</b>
    <b>Bol</b>
    <b>Bold</b>

    The script that handles this all in Speech.cs, but I'd recommend waiting until the next update since this will include a rewrite of that system, making it much easier to add new tags.

    Rather than hacking AC itself, though, you can instead look into relying on the OnStartSpeech etc custom events to take the full text and add your own custom scrolling effect.
  • edited October 2018
    I tried the custom token method, and found the [token:0] text will also be displayed during scrolling before it is totally scrolled through. Is this normal?
  • edited October 2018
    I'll look into it.
  • I can only reproduce this if the "0" token hasn't been set through script - in which case the behaviour is correct.

    Once a token's value has been set, it should be replaced with the token's value before scrolling.
  • edited October 2018
    Thanks for adding the TMP tags support in the latest version.

    About the custom token, where should I put the KickStarter.runtimeVariables.SetCustomToken (0, "<custom>"); code? When I put it in the a script that is attached to the Speech Menu canvas, [token:0] does scroll out before turning into <custom> after fully rolled out.
  • The token needs to be set before the speech is processed - which itself occurs before the Menu to display it is turned on.  You'll need to call it before the speech Action.

    However, the Speech.cs script has been updated with a much easier-to-use tag system - see the "richTextTags" variable on line 60.  If you want to add custom tags, you can just add them there - provided they require closing tags too.
  • Thanks. The new Speech.cs is super COOL!

    Would you plan to make the "adding custom tags" capability to some external locations? Like, making Speech.cs read a text field or script or a text window in the inspector, so that the custom tags won't be overwritten when AC is updated?
  • edited October 2018
    It's something I'd been considering, yes - likely from the Dialog component.
  • Thanks in advance!
  • Hello, after updating from 1.65.2 to 1.66.2, I modified Speech.cs again with

    private RichTextTag[] richTextTags = new RichTextTag[]
    {
    #if TextMeshProIsPresent
    new RichTextTag ("s"),
    new RichTextTag ("u"),
    new RichTextTag ("sub"),
    new RichTextTag ("sup"),
    new RichTextTag ("link="),
    #endif
    new RichTextTag ("b"),
    new RichTextTag ("i"),
    new RichTextTag ("size="),
    new RichTextTag ("color="),
    new RichTextTag ("c="),
    new RichTextTag ("w"),
    new RichTextTag ("w="),
    new RichTextTag ("j"),
    new RichTextTag ("j=")
    };

    But it seems now the tags are also rolled out when the text is rolling.

  • But it seems now the tags are also rolled out when the text is rolling.

    Sorry, meaning what exactly?

    The rich-text tag detection code is being re-written again as part of v1.66.4, but custom tags go in the Dialog component's Inspector on the GameEngine.

  • edited January 2019

    I mean the custom rich-text tags will be rolled out partially before it can be compiled. For example, a dialog of {w}Hello{/w}(< in place of { as the forum complies the < tags too) will be rolled out as:
    <
    <w
    H
    He
    Hel
    Hello
    Hello<
    Hello</
    Hello

    In v1.65.2 the partial roll-out of custom tags can be avoided using your instructions of modifying the richTextTags. But in v1.66.2 this way seems not working anymore...

    [quote]
    The rich-text tag detection code is being re-written again as part of v1.66.4, but custom tags go in the Dialog component's Inspector on the GameEngine.
    [/quote]

    Does it mean this feature will be handled in another way?

  • Does it mean this feature will be handled in another way?

    Not from the user perspective, no. But if there is an issue here, I'll address it.

    Forgetting about modifying Speech.cs, what happens if you insert them into Dialog's Inspector?

  • edited January 2019

    Ah it works. Sorry I didn't know the option is now in the GameEngine Dialog component. Thanks.

  • For the tags in the GameEngine Dialog's Inspector, there are some tags I need without closing tags (e.g. <q=xxx> is compiled but is not). Is it possible to add an option to the tags to choose whether it has closing tags? Or are there even better ways to work around this?

  • Closing tags are necessary for rich text, since they're used to mark what text is affected. I suppose you could try inserting e.g. <q=xxx>

    What is the effect you're trying to actually achieve?  You may be better off relying on custom speech tokens - see the Manual's "Speech event tokens" for more.

  • Hi. I wanna use this textmesh pro tag <sprite="assetName" name="spriteName">, but i can't make it not scroll. Do i have to modify something in Speech.cs? I tried using speech tags, but i don't really understand them. When i insert [token:1] to speech, it just shows as text. I'm using AC 1.68.4

  • Speech text tokens are used for text-replacement. <sprite="xx"> is a rich-text tag.

    Rich-text tags need to be handled carefully when text is scrolling, because the closing tag needs to be added on dynamically when the scroll is midway through it. Custom rich-text tags can be added from the GameEngine object's Dialog component.

    Find the Dialog component Inspector, increase the Rich Text Tags field's Size to 5, and set the last one to sprite=. You will have to enter in a closing tag into your speech text for it to work.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.