Forum rules - please read before posting.

Speech string displaying text from previous speech for a split of second

I've had this issue since I started using AC, but so far I'd managed to bypass it by making use of a slightly delayed UI animation. But the UI I'm working on at the moment would be quite a bit more complicated if I introduced unnecessary animations to it.

Here is a short video of the issue (note it doesn't happen the first time around because no characters had spoken yet):

And this is the script I've written for the Instant Messaging system:

    using UnityEngine;
    using AC;
    using TMPro;

    public class DesktopIM : MonoBehaviour
    {
        private string IMtext;
        private TextMeshProUGUI FullChat;
        public GameObject TypingBox;
        public GameObject WriteHereBox;
        public GameObject InvisibleButton;

        void OnEnable() 
        { 
            EventManager.OnStartSpeech += GetSpeech;
            EventManager.OnStopSpeech += OnStopSpeech;
        }
        void OnDisable() 
        { 
            EventManager.OnStartSpeech -= GetSpeech;
            EventManager.OnStopSpeech -= OnStopSpeech;
        }   

        public void Awake()
        {
            FullChat = this.GetComponent<TMPro.TextMeshProUGUI>();      
        }

        void GetSpeech(AC.Char speakingCharacter, string speechText, int lineID)
        {

            if (speakingCharacter.GetName() == "Rosa IM")
            {
                TypingBox.SetActive(true);
                WriteHereBox.SetActive(false);
                InvisibleButton.SetActive(false);

                IMtext = "\n<color=red>" + speakingCharacter.GetName() + ":</color> " + speechText;
            }
            else
            {

                TypingBox.SetActive(false);
                WriteHereBox.SetActive(false);
                InvisibleButton.SetActive(false);

                IMtext = "\n<color=blue>" + speakingCharacter.GetName() + ":</color> " + speechText;
            }

        }

        private void OnStopSpeech(AC.Char character)
        {
            TypingBox.SetActive(false);
            WriteHereBox.SetActive(true);
            InvisibleButton.SetActive(true);
            FullChat.text = FullChat.text + IMtext;

        }

    }

It just seems strange to me that the "TypingBox.SetActive(true)" command would be run before AC has managed to flush the previous speech string. Is this something that could be fixed?

Comments

  • edited January 2022

    Note that "Retain subtitle text buffer once line has ended" IS unchecked, but the linked TMPro component never clears the line. In fact, if I modify it manually using the inspector at runtime, it instantly reverts back as soon as I click out of the text box. "Update if string is empty?" also doesn't seem to do anything, whether it's checked or unchecked.

  • What are your AC and Unity versions?

    This can normally be rectified by checking Duplicate for each line? in your Subtitles menu, so that each line uses a separate copy of the menu with no back-buffer.

    How does the Label that displays the speech fit in with the rest of the Menu? Is that being handled by AC automatically, or is that also being set through script?

  • edited January 2022

    Unity 2021.27f1
    AC 1.74.3

    The label is being handled by AC automatically, yeah. That means the AC Menu -> Unity UI link is constantly updating the TMpro component, even when no speech is active (I assume because the AC label still contains this text), so I can't clear the TMpro text directly.

    Imo, the ideal solution would be to empty the label when OnStopSpeech is called, but I'm not sure how to go about doing this.

    Note that my setup relies on "TMPro Typewriter effect?" being unchecked (I need the text UI to expand as the text is typed rather than starting out as the final size and gradually unhiding the text), so if it is necessary to handle the link through script, this needs to be taken into account.

  • Since you have Retain subtitle text buffer once line has ended? unchecked, the text should clear as soon as the speech line ends.

    What is the Menu's "Appear type"? I can't recreate the issue, but it may be based on other settings/options in your project.

    The clearing of the text should occur at line 506 in the MenuLabel script:

    else if (!KickStarter.speechManager.keepTextInBuffer)
    {
        newLabel = string.Empty;
    }
    

    This clauses will run if the speech variable is null (checked on line 475). If you place some Debug.Log statements in these clauses, it'll tell us which one is being incorrectly run at the time.

  • Right, first this one:

    else if (!KickStarter.speechManager.keepTextInBuffer)
    {
        newLabel = string.Empty;
        Debug.Log("newLabel = string.Empty");
    }
    

    When I first run the game, this doesn't run. If I click to speak to a character using my regular speech bubbles (appear type: when speech plays), this is NEVER run.

    If I run the game and open the Instant Messenger UI right away (appear type: manual), this debug.log does run - I believe every frame. The numbers go up really quickly. If I turn the menu off, it stops. If I turn it on again, it resumes. Once I run an actionlist that plays a speech line, it stops running and never runs again.

    And for this one:

    if (line != string.Empty || updateIfEmpty)
    {
        newLabel = line;
        Debug.Log("newLabel = line");
    }
    

    This doesn't run as long as the previous one is running. However, once a speech is played, as long as the menu is open, this will run every frame.

    I also tested all of this with my regular speech bubble (because it's simpler) by changing its appear type to manual. It behaves in exactly the same way.

    If "Retain subtitle text buffer once line has ended?" is checked, the only apparent difference is that "newLabel = string.Empty" is never be printed to the console, even when a speech line has never been spoken. Otherwise the behaviour seems to be the same: whether the option is checked or not, as long as a menu with a speech element is open, there will be a speech line there, even when a speech is not currently playing. "Update if string is empty?" makes no difference because it is NEVER empty after the first speech is played.

  • edited January 2022

    Chris, I created an entire new project from scratch, imported AC and assigned the 2D Demo managers. Then I created a new AC menu, set the appear type to manual, and checked "enabled on start?". I created a new label and set its type to "Dialogue Line".

    When I run the game, the speech line stays on that menu after the regular subtitles are turned off. Both Retain subtitle text buffer once line has ended? and Update if string is empty? don't make any difference. The line stays on the menu indefinitely until a new one is spoken.

  • Thanks for the details - I will look into it.

  • As a test, open up MenuLabel.cs, and replace the line:

    if (!isDuppingSpeech && KickStarter.dialog.GetLatestSpeech () != null)
    

    with:

    if (!isDuppingSpeech)
    

    Does that resolve the issue - both in the 2D Demo and your own project?

  • It does fix the issue, in both cases! Thank you very much.

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.