Delay Continue Button?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Delay Continue Button?

Post by PayasoPrince »

Hello,

My custom dialogue UI has a Continue Button and a Button for fast forwarding. Both are currently working fine. However, I would like to add a small wait period before the player can click continue or fast forward. This way they will not accidentally skip any dialogue.

Is there anyway to add a delay before the player can click continue?
User avatar
Tony Li
Posts: 22152
Joined: Thu Jul 18, 2013 1:27 pm

Re: Delay Continue Button?

Post by Tony Li »

Hi,

Here are two ways to do that:

1. Make a subclass of StandardUISubtitlePanel. Use it for your subtitle panel. Override ShowContinueButton() to make the button non-interactable for a duration:

Code: Select all

public class MySubtitlePanel : StandardUISubtitlePanel
{
    public override void ShowContinueButton()
    {
        base.ShowContinueButton();
        continueButton.interactable = false;
        Invoke(nameof(AllowContinueButton), 0.5f); // Make interactable after 0.5 seconds
    }
    
    void AllowContinueButton()
    {
        continueButton.interactable = true;
    }
}
Or, if you don't want to make a subclass, you could just add a similar type of script to the continue button itself:

Code: Select all

public class AllowButtonAfterDelay : MonoBehaviour
{
    private void OnEnable()
    {
        GetCompponent<Button>().interactable = false;
        Invoke(nameof(AllowButton), 0.5f); // Make interactable after 0.5 seconds
    }
    
    void AllowButton()
    {
        GetComponent<Button>().interactable = true;
    }
}
Designers more often want to prevent the player from accidentally choosing a response menu item when spamming the continue button. The response menu's Standard UI Response Menu component has a Block Input Duration. If you set it to 0.5, for example, it will not allow the player to click response buttons for the first 0.5 seconds.
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Re: Delay Continue Button?

Post by PayasoPrince »

Hi, Tony

Thank you for not just always responding in a timely manner, but also providing multiple resolutions.

I went the route of adding this script to my Fast forward Button:

Code: Select all

public class AllowButtonAfterDelay : MonoBehaviour
{
    private void OnEnable()
    {
        GetComponent<Button>().interactable = false;
        Invoke(nameof(AllowButton), 0.5f); // Make interactable after 0.5 seconds
    }
    
    void AllowButton()
    {
        GetComponent<Button>().interactable = true;
    }
}
This seems to work for the first message in the conversation, but stops working when the following child message is displayed. My guess is it would need to be disabled and reenabled again after continuing.
What is the best way to apply this delay to every dialogue in the conversation? :?
User avatar
Tony Li
Posts: 22152
Joined: Thu Jul 18, 2013 1:27 pm

Re: Delay Continue Button?

Post by Tony Li »

Good catch. The continue button stays active when one line is immediate followed by another in the same subtitle panel, so it won't receive the OnEnable() message.

Instead, assuming your subtitle panel is part of the Dialogue Manager's hierarchy (e.g., instantiated into the Dialogue Manager's Canvas), you can change this method name:

Code: Select all

private void OnEnable()
to:

Code: Select all

private void OnConversationLine(Subtitle subtitle)
You'll also need to add this to the top of your script:

Code: Select all

using PixelCrushers.DialogueSystem;
If it's not in the hierarchy, you can change the method name to something else, like:

Code: Select all

public void DisableContinueButtonBriefly()  // Note: now a public method
and configure the Subtitle Text > typewriter effect's OnBegin() UnityEvent to call the method.

The other solution is to use a subclass of StandardUISubtitlePanel that overrides ShowContinueButton().
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Re: Delay Continue Button?

Post by PayasoPrince »

Strangely enough, changing the method to:

Code: Select all

private void OnConversationLine(Subtitle subtitle)
Worked for the child dialogue messages, but wasn't being applied to the first message for some reason.

I ended up needing to use both:

Code: Select all

private void OnEnable()
        {
            GetComponent<Button>().interactable = false;
            Invoke(nameof(AllowButton), 1f); // Make interactable after 1 seconds
        }
   	private void OnConversationLine(Subtitle subtitle)
        {
            GetComponent<Button>().interactable = false;
            Invoke(nameof(AllowButton), 1f); // Make interactable after 1 seconds
        }
This seems to give me the result I want but I'm not sure if using both methods will have anegative impact. :?
User avatar
Tony Li
Posts: 22152
Joined: Thu Jul 18, 2013 1:27 pm

Re: Delay Continue Button?

Post by Tony Li »

No, that's totally fine. It probably wasn't being applied to the first line because the continue button GameObject wasn't active yet since the dialogue UI was still appearing.
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Re: Delay Continue Button?

Post by PayasoPrince »

Thanks! :mrgreen:
Post Reply