Page 1 of 1

Delay Continue Button?

Posted: Sat Jan 29, 2022 7:32 pm
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?

Re: Delay Continue Button?

Posted: Sat Jan 29, 2022 8:45 pm
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.

Re: Delay Continue Button?

Posted: Sat Jan 29, 2022 10:59 pm
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? :?

Re: Delay Continue Button?

Posted: Sun Jan 30, 2022 8:21 am
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().

Re: Delay Continue Button?

Posted: Sun Jan 30, 2022 11:08 am
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. :?

Re: Delay Continue Button?

Posted: Sun Jan 30, 2022 11:40 am
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.

Re: Delay Continue Button?

Posted: Sun Jan 30, 2022 11:55 am
by PayasoPrince
Thanks! :mrgreen: