Delay a subtitle from showing in code

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
mgregoirelds
Posts: 106
Joined: Wed Aug 23, 2017 4:10 pm
Location: Canada

Delay a subtitle from showing in code

Post by mgregoirelds »

Hello,

I see that a question was asked about delaying a subtitle but the provided answer is with precreated commands of Dialogue System. How can I control when the subtitle is displayed if I'm making a custom command?

Here is my use-case that I would like to do:

1) Fade-in the text at the same time that the text is writing on screen
2) Enable continue button
3) Press Continue button
4) Fade-out current text
THEN 1) again

The problem that I get now is that upon pressing the continue button, it does not start the fade-out part. In fact, if I do the fade out part before the fade in, most of the text will already be written on screen upon my fade in. I don't really want that. Any way using code to hook some function to the continue button to actually fade out, then call my next dialogue for my fade in to start? Or delay when the text is starting to write on screen upon pressing the continue buttnon?
Unity 2022.3.17f1
Dialogue System 2.2.44.1
OpenAI Addon 1.0.12
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Delay a subtitle from showing in code

Post by Tony Li »

Hi Maxime,

One easy way is to use RPG Maker codes to pause before typing. For example:
  • Dialogue Text: "\.\.\.Hello, world."
The typewriter will pause for 3 seconds before typing "Hello, world.". By default "\." makes the typewriter pause for 1 second and "\," makes the typewriter pause for 0.25 second.

You could even use a script with an OnConversationLine method to add this to the subtitle text at runtime:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
    if (string.IsNullOrEmpty(subtitle.formattedText.text)) return;
    subtitle.formattedText.text = @"\.\.\." + subtitle.formattedText.text;
}

A completely different idea is to point the continue button's OnClick() event to your own custom script method. In the method, fade out the current text. When it's faded out, call the dialogue UI's OnContinue() method -- or the subtitle panel's OnContinue() method if you're using the Standard Dialogue UI.

For example, point the continue button's OnClick() to this method on the StandardUISubtitlePanel:

Code: Select all

void MyCustomContinue()
{
    StartCoroutine(MyContinueCoroutine());
}

IEnumerator MyContinueCoroutine()
{
    var panel = GetComponent<StandardUISubtitlePanel>();
    panel.Close();
    do
    {
        yield return null;
    } while (panel.panelState != PanelState.Closed);
    panel.OnContinue();
}
mgregoirelds
Posts: 106
Joined: Wed Aug 23, 2017 4:10 pm
Location: Canada

Re: Delay a subtitle from showing in code

Post by mgregoirelds »

Hello Tony! Great propositions, I'll test them out. Thanks a lot!
Unity 2022.3.17f1
Dialogue System 2.2.44.1
OpenAI Addon 1.0.12
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Delay a subtitle from showing in code

Post by Tony Li »

You're welcome! If those don't work out, let me know. I'm sure we can come up with a solution that works well for you.
Post Reply