Forum rules - please read before posting.

Player still moving after Pause toggle input (Direct Input)

Hello everyone,

I'm having a weird issue where when I press the "Pause" key/button the menu shows but if the player is currently moving they will keep moving even whilst the menu is shown until they hit a collision. I'm not sure exactly what's going on, I have pause game paused when the when active checked. Any help would be greatly appreciated :)

Comments

  • Are you using Active Inputs to turn the Pause menu on, or its default "On Input Key" setting, and what physics components does your Player character have? Screenshots of both would be best to understand the situation.

    We'll need to determine if this is a case of the game not pausing, or the character somehow moving while the game is paused.

    Enable the AC Status box via the bottom of the Settings Manager. At the time the issue occurs, check the box in the top-right corner of the Game window - what is the "Game state" set to?

  • I'm using the default On Input Key. Unfortunately, I'm not at my PC at the moment so I shall check but doing some testing this morning I found that ANY menu that I open with a key press allows the player to continue to move, even with pause game checked. I shall post my results from the test when I get a chance.
  • Ok, so as for the physics component, it's using whatever the default 2D character wizard made with it as I don't think I've changed anything. The AC Status box states that the game is paused when the player is still moving.

    Should be easy to replicate if you change the movement to direct, change the menu to appear to On Key Input, and just hold down a directional key and press the "menu" key to bring up that menu whilst walking.

  • Such a Menu exists with the 2D Demo, but switching the movement to Direct and clearing the pause background from the Menu Manager (so that the game is still visible) does not cause the issue on my end.

    Is the same true for you with the 2D Demo?

  • edited October 2022

    That's very odd, it seems to work fine in the 2D demo. I'm not sure what's the cause. I'll scrub through the differences and see if I can find anything out of place. Any ideas on what it could be?

    P.S What's also odd is that I used all my asset files in the 2d demo and it still worked. It just won't work in my new scene.

    EDIT: I just figured out the problem! I'm using a particle system that uses unscaled time. through a custom script. If I add a toggle to turn it on and off only when the pause menu is open it should work as normal, right?

  • A particle system with unscaled time alone shouldn't cause an issue - at least it doesn't on my end. It may be to do with the custom script that calls it.

    To make a change at the time the game pauses and unpauses, you can hook into the OnEnterGameState / OnExitGameState custom events:

    using UnityEngine;
    using AC;
    
    public class GameStateEventExample : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            EventManager.OnEnterGameState += EnterGameState;
            EventManager.OnExitGameState += ExitGameState;
        }
    
    
        private void OnDisable ()
        {
            EventManager.OnEnterGameState -= EnterGameState;
            EventManager.OnExitGameState -= ExitGameState;
        }
    
    
        private void EnterGameState (GameState gameState)
        {
            if (gameState == GameState.Paused)
            {
                // Game was paused
            }
        }
    
    
        private void ExitGameState (GameState gameState)
        {
            if (gameState == GameState.Paused)
            {
                // Game was unpaused
            }
        }
    
    }
    
  • Thanks again, Chris! This will be most useful!

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.