1
votes

I'm trying the new Unity Input System and so far it's working great. However, I ran into a small snag. I want to implement a 'pause' system. When the game is paused, the player controls should be disabled. And when the game is resumed the player controls should be back in working order. This half works. I successfully disable the player controls when the game is paused, yet when the game is resumed the controls still don't work.

Part of the class responsible for movement:

public class ShapeMover : MonoBehaviour
{
    public InputManager controls;

    private       float        _lastFallTime;
    private       float        _fallSpeed;
    private       ShapeSpawner _spawn;
    private       GameObject   _shapeToMove;
    private       Transform    _shapeToMoveTransform;
    private       bool         _isGameOver;
    private const float        _leftRotationAngle  = (float) -1.57079633;
    private const float        _rightRotationAngle = (float) 1.57079633;


    private void Awake()
    {
        _spawn        = FindObjectOfType<ShapeSpawner>();
        _lastFallTime = 0f;
        _fallSpeed    = GameGrid.Instance.GetFallSpeed();
        _isGameOver   = false;

        controls.Player.Movement.performed += ctx => Movement(ctx.ReadValue<Vector2>());
        controls.Player.Drop.performed     += ctx => Drop();
        controls.Menu.Reset.performed      += ctx => Restart();
        controls.Menu.Pause.performed      += ctx => PauseToggle();

        SetShapeToMove();
    }

Pause function in the same class:

private void PauseToggle()
{
    var currentPauseState = GameGrid.Instance.IsPaused;
    //If not paused, will pause
    if (!currentPauseState)
    {
        controls.Player.Disable();
        GameGrid.Instance.IsPaused = true;
    }
    else
    {
        controls.Player.Enable();
        GameGrid.Instance.IsPaused = false;
    }
}

Am I doing something wrong? How can I achieve the desired behavior?

1
Just out of curiosity, what happens if you enable player controls after setting IsPaused to false? - SharpNip
I suspect that by disabling controls, you have disabled the thing that handles changing the pause state! - Draco18s no longer trusts SE
@SharpNip If IsPaused set to false, the controls don't respond. - Curtwagner1984
@Draco18s That's not the case, because I can still pause and unpause after I paused for the first time. (It's just that after I unpause the player controls don't work, but the pause controls still do) - Curtwagner1984
Then there is not enough code here for us to solve the problem. - Draco18s no longer trusts SE

1 Answers

0
votes

The issue seems to be solved in the new version of the Input System. To resolve the issue one needs to update to Input System 0.2.8+

When upgrading one can run into this problem.