Page 1 of 2
Disable Continue Button key On Pause
Posted: Sun Apr 12, 2020 1:52 pm
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.
Re: Disable Continue Button key On Pause
Posted: Sun Apr 12, 2020 4:01 pm
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.
Re: Disable Continue Button key On Pause
Posted: Mon Apr 13, 2020 1:42 pm
by ko_games
Thanks Tony! That worked perfect! You are awesome!
Re: Disable Continue Button key On Pause
Posted: Mon Apr 13, 2020 2:05 pm
by Tony Li
Happy to help!
Re: Disable Continue Button key On Pause
Posted: Fri Oct 01, 2021 4:28 pm
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?
Re: Disable Continue Button key On Pause
Posted: Fri Oct 01, 2021 11:13 pm
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;
....
Re: Disable Continue Button key On Pause
Posted: Sat Oct 02, 2021 5:29 pm
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
Re: Disable Continue Button key On Pause
Posted: Sat Oct 02, 2021 5:44 pm
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.
Re: Disable Continue Button key On Pause
Posted: Sat Oct 02, 2021 6:01 pm
by fallingstarint
Hi,
Indeed, the problem was that in the inspector I needed to refer the button for it to be selectable. Thanks Tony.
Re: Disable Continue Button key On Pause
Posted: Sat Oct 02, 2021 6:55 pm
by Tony Li
Glad to help!