Forum rules - please read before posting.

Speech formatting and Unity UI

I use a Unity UI menu as a speech bubble, with a label linked to a TMP object. If I run a speech action with <i></i> tags, though, the displayed text isn't formatted. If I duplicate the UI and change the source to AC, then that one does display the formatting.

I use this script to add a short delay before the speech bubble:

public class DelayScrolling : MonoBehaviour
{

    private void OnEnable() { EventManager.OnStartSpeech_Alt += StartSpeech; }
    private void OnDisable() { EventManager.OnStartSpeech_Alt -= StartSpeech; }

    private void StartSpeech(Speech speech)
    {

        if (speech.GetSpeaker() == "Narrator" | speech.GetSpeaker() == "Narrator Intro")
        {           
            speech.ReplaceDisplayText("[wait:0.1]" + speech.OriginalText);
            return;

        }
        Debug.Log(speech.OriginalText);
        speech.ReplaceDisplayText("[wait:0.3]" + speech.OriginalText);
    }

}

What I've noticed is that console message from the debug.log above displays the italicised word rather than the word and the tags around it. I think this means that the formatting is being processed even before the [wait:x] tags, and this formatting is not being carried over to the TMP text box.

I'm a bit reticent to ask for a fix because I use a rather convoluted speech bubble that (1) uses the TMP typewriter effect, and (2) copies its size from a dummy TMP object that doesn't use the typewriter effect (the dummy gets its text from menu.speech.FullText). Basically, I don't want to break this solution in order to get text formatting, but it would be really nice if we could have it without causing issues.

Comments

  • edited September 2022

    The Console output processes tags as it sees them - the <i> tags should still be there. Though, to be sure you can temporarily unhook the StartSpeech event until the issue is resolved.

    When you say the tags aren't formatted, do you mean they remain in the text ("<i>Hello</i> there"), or they're removed without effect ("Hello there")?

    If you're passing the text to a dummy TMPro object (presumably hidden by default), does that properly process the tags? Check that your TMPro objects display such tags when AC is not involved, i.e. by manually entering text into their Text fields and unhooking them from AC.

  • edited September 2022

    Thanks for looking into it, Chris. Yes, I unhooked the StartSpeech event, and it doesn't affect the issue.

    I mean they are removed without the effect ("Hello there"). If I pause the game at runtime in the editor as the speech is displayed and check the TMP object instantiated in the scene, the TMP text field doesn't include the tags (but an AC menu, displayed at the same time, does show the italics).

    I've just checked, and both the dummy and the TMP object linked to the AC label process the tag if the tag is typed in manually (so my fears that fixing the issue would affect the dummy size are unfounded). So as long as fixing it doesn't mess with the AC subtitle display time, passing the tags to TMP object shouldn't break anything.

  • the dummy gets its text from menu.speech.FullText

    Copy it from menu.speech.OriginalText - FullText will omit the tags, but OriginalText should retain them.

  • edited September 2022

    This works for the dummy out of the screen, but the actual TMP text object linked to the AC menu label is still the same. To be clear, I don't manipulate the text inside the real speech bubble in any way, only its size, which is copied from the dummy. So it's good that we got the dummy displaying exactly the same thing we want the real speech bubble to display, but we still need that last step there.

  • Wait, I spoke too soon.

    The dummy doesn't actually work with OriginalText because not only does it include formatting tags (i.e. <i></i>, <b></b>, etc), but also AC tags like [wait:x]. I assume this is why the AC menu link is stripping the text of all tags: presumably it's using FullText so that its own speech tags aren't displayed by TMP?

    Basically, we need something between FullText and OriginalText, where the formatting tags that can be parsed by TMP stay, while removing the AC speech tags.

  • To be clear, I don't manipulate the text inside the real speech bubble in any way, only its size, which is copied from the dummy.

    I can't recreate the issue of a TMPro-linked Label element not correctly processing rich-text tags. The text, with tags, should be passed onto the TMPro Text component.

    Basically, we need something between FullText and OriginalText, where the formatting tags that can be parsed by TMP stay, while removing the AC speech tags.

    For that, you can use the Speech's log.textWithRichTextTags property.

  • edited September 2022

    Are you sure you can't reproduce it? I've gone over all my scripts and can't find anything that would affect this. I did do some more testing and narrowed it down to the "TMPro Typewriter Effect?" checkbox. If you turn it off, then AC feeds the component one character at a time WITH tags (very neat how it does this, btw, looking ahead, including both opening and closing tags first, then the text in the middle). But if you check the box, the text is stripped down of all formatting tags. The thing is that I really do need to use the effect because I don't want words to start being written in one line, reach the width limit and then drop down to the next line when they've already been partially typed.

    I was going to say I wasn't sure this was a TMPro or AC issue at this point, but then I paused the game mid-speech, looked for the instantiated UI object, and tried adding tags manually. As soon as I unpaused the game, the TMPro component was updated to remove the tags, which I believe means AC is constantly feeding it the tagless lines as long as the speech is active? Unless this is something TMPro itself does when its typewriter effect is being used, but it sounds unlikely.

  • The checking of "TMPro Typewriter effect?" was the missing detail. I will look into this further.

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.