Can't switch action map for pause menu

I don’t think I fully understand the new input system. I want to switch my action map while the player is in a pause menu, to an action map with only one keybinding – escape (to exit the pause menu). All other keybindings, such as left clicking the mouse – should be disabled.

Based on my code below, I’ve confirmed I switched the action map with playerInput.currentActionMapBut the player continues to be able to click on other UI elements after I’ve switched the action map. Strangely, my code often disables the escape key.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class Pause : MonoBehaviour
{
    public GameObject pauseScreen;

    public static bool gameIsPaused;

    public PlayerInput playerInput;

    public void OnPause(InputAction.CallbackContext context)
    {
        if (context.started)
        {
            gameIsPaused = !gameIsPaused;

            PauseGame();
        }
    }

    void PauseGame()
    {
        if (gameIsPaused) // pauses game
        {
            playerInput.actions.Disable();
            playerInput.SwitchCurrentActionMap("Pause");
            pauseScreen.SetActive(true);
            AudioListener.pause = true;
            Time.timeScale = 0;
        }
        else // unpauses game
        {
            playerInput.actions.Enable();
            playerInput.SwitchCurrentActionMap("Gameplay");
            pauseScreen.SetActive(false);
            AudioListener.pause = false;
            Time.timeScale = 1;
        }
    }
}

I’ve also tried to do the same through the inspector. I “Invoke Unity Events” in Behavior, click on my Gameplay action map, then under the Pause keybinding, I drag my player controller over, select PlayerInput.SwitchCurrentActionMap, and type Pause in the string (see attached image). Like the code, this doesn’t seem to disable my Gameplay action map, since I can continue to click on my UI elements when the game is paused.

Clearly, I’m not doing something correctly. Does anyone have any ideas or experience with this?

8245575--1078695--Inspector.png

I figured it out when working on another problem (isn’t that how it often happens? Maybe the brain needs some rest). I had two PlayerInput modules in the game. I deleted the one, and now the switch action map works.