Disable Continue Button key On Pause

Announcements, support questions, and discussion for the Dialogue System.
ko_games
Posts: 29
Joined: Wed Jan 08, 2020 3:20 am

Disable Continue Button key On Pause

Post by ko_games »

In my game when the game is paused the time scale is set to 0. Everything in the game is paused except for my pause menu which is then displayed. However, I noticed that if the player pauses the game while in the middle of a dialogue the player can still advance the dialogue by pressing the ENTER key (The enter key is set in the Input Device Manager. The current settings for the Dialogue system have the continue button set to always). How can I disable the enter key input while the game is paused so the player doesn't accidentally advance the conversation while the game is paused? I tried using the Dialogue Time Modes Gameplay and Realtime, but this did not work.
User avatar
Tony Li
Posts: 22158
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disable Continue Button key On Pause

Post by Tony Li »

Hi,

When the Dialogue System's Input Device Manager > Mode is Keyboard or Joystick, or if Always Auto Focus is ticked, the topmost Dialogue System UI panel will ensure that one of its buttons is always selected (focused). When you're showing a subtitle, the subtitle panel's continue button will stay selected. When the player presses the Event System's Submit input (e.g., Enter key), it will click the current selection.

When you open your pause menu, tell Dialogue System UI panels to stop doing this focus check. To do that, set UIPanel.monitorSelection to false. You'll probably also want to clear the Unity UI Event System's current selection, or set it to one of the buttons in your pause panel. Do this after one frame to allow your pause menu's UI elements to become active; otherwise they might not be able to accept focus. Example:

Code: Select all

void OpenPauseMenu()
{
    Time.timeScale = 0;
    UIPanel.monitorSelection = false;
    myMenuPanel.SetActive(true);
    StartCoroutine(ClearSelectionAfterOneFrame());
}

IEnumerator ClearSelectionAfterOneFrame() // Could select a pause menu button instead.
{
    yield return null;
    UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(null);
}

void ClosePauseMenu()
{
    myMenuPanel.SetActive(false);
    Time.timeScale = 1;
    UIPanel.monitorSelection = true;
}

If you're using the UI Button Key Trigger component, in version 2.2.6 it has a similar new static bool UIButtonKeyTrigger.monitorInput that you can set to false to prevent your UI Button Key Triggers from checking input.
ko_games
Posts: 29
Joined: Wed Jan 08, 2020 3:20 am

Re: Disable Continue Button key On Pause

Post by ko_games »

Thanks Tony! That worked perfect! You are awesome!
User avatar
Tony Li
Posts: 22158
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disable Continue Button key On Pause

Post by Tony Li »

Happy to help! :-)
fallingstarint
Posts: 22
Joined: Fri Oct 01, 2021 11:50 am

Re: Disable Continue Button key On Pause

Post by fallingstarint »

Hello,

sorry to dig this up but this is, after hours of researches on Google and the forum, the only post where you talk clearly about pausing the dialogue system and I can't get my head around it.

I have the same system where the game is paused based on timescale.

Now, when I pause the game, the dialogue still goes on until it hits a response menu. Otherwise, everything keeps running and the "continue button" is still clickable on joysticks.

I also set my dialogue time to GAMEPLAY.

Here is my code:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;



public class PauseController : MonoBehaviour
{
    public static bool gameIsPaused;
    public bool pausedGame;

    void Update()
    {
        if (Input.GetButtonDown("Pause"))
        {
            gameIsPaused = !gameIsPaused;
            
            PauseGame();
        }
    }

    void PauseGame()
    {
        if (gameIsPaused)
        {
            Time.timeScale = 0f;
            pausedGame = true;
            PixelCrushers.UIPanel.monitorSelection = false; // Don't allow dialogue UI to steal back input focus.
            PixelCrushers.UIButtonKeyTrigger.monitorInput = false; // Disable hotkeys.
            PixelCrushers.DialogueSystem.DialogueManager.Pause(); // Stop DS timers (e.g., sequencer commands).
            


        }
        else
        {
            Time.timeScale = 1;
            pausedGame = false;
            PixelCrushers.UIPanel.monitorSelection = true; // Allow dialogue UI to steal back input focus again.
            PixelCrushers.UIButtonKeyTrigger.monitorInput = true; // Re-enable hotkeys.
            PixelCrushers.DialogueSystem.DialogueManager.Unpause(); // Resume DS timers (e.g., sequencer commands).
           
        }
    }
}
What am I missing? :(
User avatar
Tony Li
Posts: 22158
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disable Continue Button key On Pause

Post by Tony Li »

Hi,

If the issue is that you don't want the dialogue UI elements to be clickable by the mouse when the game is paused, I suggest disabling the Dialogue Manager Canvas's GraphicRaycaster component. Example:

Code: Select all

...
DialogueManager.displaySettings.defaultCanvas.GetComponent<GraphicRaycaster>().enabled = !gameIsPaused;

if (gameIsPaused)
{
    Time.timeScale = 0f;
....

If you want to disable the continue button entirely, so it can't also be clicked by gamepad or keyboard, you'll need to find the continue button(s) and set their interactable properties. Example:

Code: Select all

...
foreach (panel in DialogueManager.standardDialogueUI.conversationUIElements.subtitlePanels)
{
    if (panel.continueButton != null) panel.continueButton.interactable = !gameIsPaused;
}

if (gameIsPaused)
{
    Time.timeScale = 0f;
....
fallingstarint
Posts: 22
Joined: Fri Oct 01, 2021 11:50 am

Re: Disable Continue Button key On Pause

Post by fallingstarint »

Hi Tony,

thank you for your reply but I already tried both of these solutions and none work either.

Whenever I pause during a dialogue, the button appears and it is still clickable or usable with a joystick.

That's a serious problem to be :(
User avatar
Tony Li
Posts: 22158
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disable Continue Button key On Pause

Post by Tony Li »

Hi,

If you set the button interactable, it won't be clickable. When you pause, please confirm that the button's interactable property is false.
fallingstarint
Posts: 22
Joined: Fri Oct 01, 2021 11:50 am

Re: Disable Continue Button key On Pause

Post by fallingstarint »

Hi,

Indeed, the problem was that in the inspector I needed to refer the button for it to be selectable. Thanks Tony.
User avatar
Tony Li
Posts: 22158
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disable Continue Button key On Pause

Post by Tony Li »

Glad to help!
Post Reply