Conversant continuing to talk - how to control the fade out / fade in of each line?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Jamez0r
Posts: 59
Joined: Fri Nov 20, 2020 8:18 pm

Conversant continuing to talk - how to control the fade out / fade in of each line?

Post by Jamez0r »

Hi Tony :D

I finished reading the documentation, and have been customizing my UI. Just for reference, the setup I'm aiming for is very simple (compared so some of the stuff I see you guys doing haha). The player never speaks, only the NPC conversant speaks. The player occasionally gets response options. The NPC subtitle panel is really simple - a subtle black background at the bottom of the screen with the dialogue line on top. Each dialogue line would be just a sentence or two long.

Image

I believe the only question I'm still not sure about is how to have more fine-tuned control over what happens when you press the continue button, and the NPC goes from saying one line to their next line. I'm not using the Typewriter effect, instead I would like to fade in and out each dialogue line.

What I would like to happen:
1) NPC's dialogue line fades in
2) Nothing happens until the player presses the continue button
3) Once the player hits continue, the current line of dialogue quickly fades out, and the next line fades in.

If the player presses continue while the current dialogue line is fading in, I'd like it to instantly begin fading out to go to the next line.

--

I started with the Letterbox prefab, and adjusted the look of the UI. I tried adjusting the Show and Hide animation state transition timings (set the transitions to 1 second for testing). This is what currently happens:
1) NPC dialogue line fades in
2) Nothing happens until player presses continue button (correct)
3) Once the player hits continue, the dialogue line instantly changes to the next line at full Alpha, then fades out (Hide transition) and fades back in (Show transition).

I had found this post that was soooort of similar to what I'm looking to do: https://www.pixelcrushers.com/phpbb/vie ... ade#p12987
In that post you suggested the option of having some custom code called when the Continue button is pressed. Is that necessary, or might there be a way to set up a default Sequence to achieve this fade effect? I have no problem setting up custom code, but thought it might be nicer and more self-contained if it was possible to set it up with a default Sequence.

Thanks for any help, loving the asset and what it can do!
User avatar
Tony Li
Posts: 22050
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conversant continuing to talk - how to control the fade out / fade in of each line?

Post by Tony Li »

Hi,

I was going to suggest a short custom script, but it's something I had on the list to add to the core subtitle panel script anyway, so here's a patch:

DS_SubtitlePanelPatch_2020-11-27.unitypackage

Import the patch, and tick 'Wait For Close' on your Standard UI Subtitle Panel component. You'll also want to change the animator controller's transitions to go between Show and Hide instead of independently linking from Any State. (See the example below.)

Here's a simple example scene:

DS_FadeBetweenLinesExample_2020-11-27.unitypackage
Jamez0r
Posts: 59
Joined: Fri Nov 20, 2020 8:18 pm

Re: Conversant continuing to talk - how to control the fade out / fade in of each line?

Post by Jamez0r »

Tony Li wrote: Sun Nov 22, 2020 8:51 pm Hi,

I was going to suggest a short custom script, but it's something I had on the list to add to the core subtitle panel script anyway, so here's a patch:

DS_SubtitlePanelPatch_2020-11-22.unitypackage

Import the patch, and tick 'Wait For Close' on your Standard UI Subtitle Panel component. You'll also want to change the animator controller's transitions to go between Show and Hide instead of independently linking from Any State. (See the example below.)

Here's a simple example scene:

DS_FadeBetweenLinesExample_2020-11-22.unitypackage
Hey Tony, thanks a ton! Works great, and I like being able to adjust the timings and such on the Animators. Cool setup!

Probably not worth mentioning but juuuust in case someone else somehow ends up in the same situation - my setup was working fine before applying the patch, but then after applying the patch my Text stopped appearing and the Animator on my NPC Subtitle Panel was stuck in Start state. The example Tony posted worked fine, so it was definitely something with my setup. Turns out I had somehow removed the "NPC Subtitle Panel" from the list of Subtitle Panels in the Standard Dialogue UI component on the "Letterbox Template Standard Dialogue UI" gameobject. Maybe I did something weird like duplicating the PC Subtitle Panel to replace the NPC Subtitle Panel, and so it got removed from the list in the process? I added it back (and made sure Element 0 was NPC and Element 1 was PC), and everything was good to go!

Thanks again!
User avatar
Tony Li
Posts: 22050
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conversant continuing to talk - how to control the fade out / fade in of each line?

Post by Tony Li »

Happy to help!
Jamez0r
Posts: 59
Joined: Fri Nov 20, 2020 8:18 pm

Re: Conversant continuing to talk - how to control the fade out / fade in of each line?

Post by Jamez0r »

Hi Tony - I'd like to have the Response panel also wait for the previous dialogue to fade out before it fades in (I have all of the text for dialogue, including the responses, stacked in the same spot at the bottom of the screen).

Should I set up a custom script for that?
User avatar
Tony Li
Posts: 22050
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conversant continuing to talk - how to control the fade out / fade in of each line?

Post by Tony Li »

Yes, writing a subclass of StandardDialogueUI is probably the way to go. If you only needed to delay the menu's fade-in until the subtitle fades out, you could adjust the animation. If the subtitle fades over 0.5 seconds, then you could make the menu's fade-in animation do nothing for the first 0.5 seconds and then fade in. However, this won't address the timing after the menu. When you click a menu button, it would fade out while the next subtitle simultaneously fades in (since they're designed by default to cross-fade).

So, instead, make a subclass of StandardDialogueUI and override ShowSubtitle() and ShowResponses().

In ShowResponses(), wait for all subtitle panels' panelState properties to become Closed. Then call base.ShowResponses().

In ShowSubtitle(), wait for the response menu panel's panelState to become Closed. Then call base.ShowSubtitle().
Jamez0r
Posts: 59
Joined: Fri Nov 20, 2020 8:18 pm

Re: Conversant continuing to talk - how to control the fade out / fade in of each line?

Post by Jamez0r »

Tony Li wrote: Tue Nov 24, 2020 1:19 pm Yes, writing a subclass of StandardDialogueUI is probably the way to go. If you only needed to delay the menu's fade-in until the subtitle fades out, you could adjust the animation. If the subtitle fades over 0.5 seconds, then you could make the menu's fade-in animation do nothing for the first 0.5 seconds and then fade in. However, this won't address the timing after the menu. When you click a menu button, it would fade out while the next subtitle simultaneously fades in (since they're designed by default to cross-fade).

So, instead, make a subclass of StandardDialogueUI and override ShowSubtitle() and ShowResponses().

In ShowResponses(), wait for all subtitle panels' panelState properties to become Closed. Then call base.ShowResponses().

In ShowSubtitle(), wait for the response menu panel's panelState to become Closed. Then call base.ShowSubtitle().
Hey Tony! Thanks again for all of the help.

I am having a bit of a struggle with this - I created the subclass of StandardDialogueUI:

Code: Select all

public class StandardDialogueUICustom : StandardDialogueUI
{

    //Delay showing Subtitles until the Response Menu is Closed
    public override void ShowSubtitle(Subtitle subtitle) {
        StartCoroutine(ShowSubtitleCustomCoroutine(subtitle));
    }

    IEnumerator ShowSubtitleCustomCoroutine(Subtitle subtitle) {
        do {
            yield return null;
        } while (PanelUninitializedOrClosed(conversationUIElements.defaultMenuPanel) == false);
        base.ShowSubtitle(subtitle);
    }


    //Delay showing the Response Menu until both the NPC & PC Subtitle Panels are Closed
    public override void ShowResponses(Subtitle subtitle, Response[] responses, float timeout) {
        StartCoroutine(ShowResponsesCustomCoroutine(subtitle, responses, timeout));
    }

    IEnumerator ShowResponsesCustomCoroutine(Subtitle subtitle, Response[] responses, float timeout) {
        do {
            yield return null;
        } while (PanelUninitializedOrClosed(conversationUIElements.defaultNPCSubtitlePanel) == false || PanelUninitializedOrClosed(conversationUIElements.defaultPCSubtitlePanel) == false);
        base.ShowResponses(subtitle, responses, timeout);
    }

    //Check if a Panel is Uninitizlied or Closed
    public bool PanelUninitializedOrClosed(UIPanel panel) { return panel.panelState == PanelState.Uninitialized || panel.panelState == PanelState.Closed; }

    
}
When I use this, the first subtitle in a conversation shows up, but the Continue button doesn't (so I can't progress any further in the conversation).

If I comment out the Override functions in this custom subclass of the StandardDialogueUI, everything goes back to working as expected (so it doesn't seem to be a "reference" issue with the Continue button).

Any ideas? Thanks a lot!!!
User avatar
Tony Li
Posts: 22050
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conversant continuing to talk - how to control the fade out / fade in of each line?

Post by Tony Li »

I went ahead and added a 'Wait For Close' checkbox to the menu panel, too. Here are the updated patch and example scene:

DS_SubtitlePanelPatch_2020-11-27.unitypackage

DS_FadeBetweenLinesExample_2020-11-27.unitypackage
Jamez0r
Posts: 59
Joined: Fri Nov 20, 2020 8:18 pm

Re: Conversant continuing to talk - how to control the fade out / fade in of each line?

Post by Jamez0r »

Tony Li wrote: Fri Nov 27, 2020 12:12 pm I went ahead and added a 'Wait For Close' checkbox to the menu panel, too. Here are the updated patch and example scene:

DS_SubtitlePanelPatch_2020-11-27.unitypackage

DS_FadeBetweenLinesExample_2020-11-27.unitypackage
Aww thanks Tony, you're the man!

Popped in the patch, and it works great!
User avatar
Tony Li
Posts: 22050
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conversant continuing to talk - how to control the fade out / fade in of each line?

Post by Tony Li »

Glad to help!
Post Reply