Changing to a different Action Map?

How can I switch to a different Action Map using code? Is there a way to disable and enable action maps? I haven’t been able to find it. I’m using the Player Input component and this is what my code looks like so far, save for the random other controls:

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

public class PlayerControlsManager : MonoBehaviour
{
    public PlayerInventory playerInventory;
    public PlayerControls controls;

    void Awake()
    {
        controls = new PlayerControls();
        playerInventory = this.gameObject.GetComponent<PlayerInventory>();
        playerMovement = this.gameObject.GetComponent<PlayerMovement>();

        controls.Gameplay.Interact.started += ctx =>
            playerInventory.heldInteract = true;

        controls.Gameplay.Interact.canceled += ctx =>
            playerInventory.heldInteract = false;
    }

    public void OnEnable()
    {
        controls.Enable();
    }

    public void OnDisable()
    {
        controls.Disable();
    }

    public void OnKillControls(){
        Debug.Log("Disabling Controls!");
        controls.Gameplay.Disable();
    }
}

I use PlayerInput.SwitchCurrentActionMap(“OtherActionMap”). But I don’t do it “in code”. With PlayerInput, I switch the actionmap when I press a certain button on my controller:

Now if I press RightStick on my gamepad, it triggers the above, and the remaining gamepad buttons are automatically mapped to the Character actionmap, thereby extending my controller’s functionality (at the cost of complicating things a bit for the end-user perhaps). Example in a game context: I can have a character crouch with the X key when on foot but if I move that character next to a car and press RightStick, the character opens the door of the car and gets in while the actionmap is changed to Driving. Now X will make the car brake (as one doesn’t usually crouch in a car). Or a more common scenario would be pressing the “Options” button on my controller to enable my menu UI while switching to the UI actionmap.

5 Likes

Thank you so much! I had no idea it could be this straight-forward. Appreciate it.