Search Unity

Question Switch action maps without releasing input

Discussion in 'Input System' started by Panzerhandschuh, Jan 4, 2021.

  1. Panzerhandschuh

    Panzerhandschuh

    Joined:
    Dec 4, 2012
    Posts:
    17
    I am running into an issue where switching from a "Menu" action map to a "Game" action map is requiring the player to release a button that is shared between the two maps. Both my menu "Select" action and vehicle "Accelerate" action are mapped to the same button (Button South). When the player resumes the game with the Select action, the Accelerate action is ignored until the player releases and re-presses the button.

    Is there any way to get the Accelerate action to become active immediately after switching action maps?

    Here's some code showing what I am trying to accomplish:

    Code (CSharp):
    1. public class Player : MonoBehaviour
    2. {
    3.     public PlayerInput playerInput;
    4.     private void Update()
    5.     {
    6.         // Action map is set to "Menu" by default
    7.         if (playerInput.actions["Select"].ReadValue<float>() > 0f) // This action is on the "Menu" action map
    8.         {
    9.             print("Select");
    10.             playerInput.SwitchCurrentActionMap("Game");
    11.         }
    12.  
    13.         if (playerInput.actions["Accelerate"].ReadValue<float>() > 0f) // This action is on the "Game" action map
    14.         {
    15.             // I want this code to run immediately after calling SwitchCurrentActionMap, but it is false until the player releases and re-presses the button
    16.             print("Accelerate");
    17.         }
    18.     }
    19. }
    20.  
     
  2. Panzerhandschuh

    Panzerhandschuh

    Joined:
    Dec 4, 2012
    Posts:
    17
    I know this is an old post, but I finally found a fix. Changing the Action Type from "Button" to "Value" allows you to switch action maps without having to release the shared button.

    upload_2021-7-12_15-47-43.png