Forum rules - please read before posting.

Locking Pause Menu during Conversation

Hello everybody, I'm tuning the final touches for my game ENCODYA.
Is there a way to lock the Pause Menu (currently assigned with input MENU - key ESC) during conversations?
I don't want the user to pause the game while talking with characters, save, etc...
Is it possible to lock it for all the dialogues? Without adding an action to lock it to all the dozens of conversations I've already in my game (it'll take me forever to do that manually)? Like some automatism (a script?) that order "Lock Pause Menu during Conversations"...?
Thanks a lot!

Comments

  • I suspect by "Conversations", you're referring to the whole dialogue exchange sequence, and not just the time that dialogue options are displayed on-screen.

    You can hook into the OnEnterGameState event to lock the pause menu when options are displayed, and unlock it when gameplay next resumes:

    using UnityEngine;
    using System.Collections;
    using AC;
    
    public class LockPauseDuringConversations : MonoBehaviour
    {
    
        private Menu pauseMenu;
    
        private void OnEnable ()
        {
            EventManager.OnEnterGameState += OnEnterGameState;
        }
    
    
        private void OnDisable ()
        {
            EventManager.OnEnterGameState -= OnEnterGameState;
        }
    
    
        private void OnEnterGameState (GameState gameState)
        {
            if (pauseMenu == null) pauseMenu = PlayerMenus.GetMenuWithName ("Pause");
    
            switch (gameState)
            {
                case GameState.DialogOptions:
                    pauseMenu.isLocked = true;
                    break;
    
                case GameState.Normal:
                    pauseMenu.isLocked = false;
                    break;
            }
        }
    
    }
    
  • Yes I meant in the whole dialogue exchange sequence.
    Thanks a lot, will try!

  • Ok, this works for the dialogue options...
    But what if I want to disable it in the whe whole dialogue exchange?

  • That's already its intent. It should resume after the exchange, provided the exchange blocks gameplay. Try it in the 2D or 3D Demo.

  • Ok I was doing something wrong earlier (not sure what).
    Works great now!
    THANKS!

  • (the only thing I noticed is that the trigger is the Dialogue Options... if it's a dialogue that has no options, but just 2 characters talking each other, then the Pause Menu is still active)

  • A dialogue with no options is not a Conversation - at least so far as AC naming convention goes.

    To have the pause menu lock whenever anyone speaks, hook insted into the OnStartSpeech event:

    using UnityEngine;
    using System.Collections;
    using AC;
    
    public class LockPauseDuringConversations : MonoBehaviour
    {
    
        private Menu pauseMenu;
    
        private void OnEnable ()
        {
            EventManager.OnStartSpeech += OnStartSpeech;
            EventManager.OnEnterGameState += OnEnterGameState;
        }
    
    
        private void OnDisable ()
        {
            EventManager.OnStartSpeech -= OnStartSpeech;
            EventManager.OnEnterGameState -= OnEnterGameState;
        }
    
    
        private void OnStartSpeech (Char speakingCharacter, string speechText, int lineID)
        {
            if (KickStarter.stateHandler.IsInCutscene ())
            {
                SetPauseMenuLockState (true);
            }
        }
    
    
        private void OnEnterGameState (GameState gameState)
        {
            if (gameState == GameState.Normal)
            {
                SetPauseMenuLockState (false);
            }
        }
    
    
        private void SetPauseMenuLockState (bool state)
        {
            if (pauseMenu == null) pauseMenu = PlayerMenus.GetMenuWithName ("Pause");
            pauseMenu.isLocked = state;
        }
    
    }
    
  • edited October 2023

    To have the pause menu lock whenever anyone speaks, hook insted into the OnStartSpeech event:

    @ChrisIceBox Hi, Chris. Seems the Menu:Change State: Lock Menu action doesn't work for locking my "Pause" menu after adding this code. I want to lock it manually sometimes.

  • The code above locks/unlocks the Pause menu automatically - if you lock it via Action, the code will override it if run afterwards.

    If you're locking the menu, it's best to do it from one place so that you have no conflicts elsewhere. What are the exact conditions you're looking to lock the menu under?

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.