[Solved] New input system, switch action map

Hello everyone,
I’m trying to switch the actionmap in my game to go from “Player” pattern of input to “UI” one , but no matter what i’ve done my computer freeze and i only can shutdown Unity.

For example, I have tried this one :

player_input.SwitchCurrentActionMap(player_input.actions.GetActionMap("Player").id);

and this one :

player_input.currentActionMap = player_input.actions.GetActionMap("Player");

But impossible to change in runtime the actionmap used.

Im using the PlayerInput component with Unity Events behavior that call on a another script the events assiociated.

If you have a solution, or at least the process to inform the devellopers, I would be gratefull.

Ok it seems the problem is qite related to this threrad from january => New Input System: Multiple Action Maps ,
any news so far ?

Problem solved, the input system called the event multiple times in a frame, that’s lead to some impredictable behaviour in the function. I have pass through with a boolean that restrict to only one pass, but it’s quite dirty. When I find a better solution, i will write down here.

2 Likes

Thanks, this helped. I used PressOnly interaction for my action to fix this. Press and release events being sent together freeze the editor.

2 Likes

Hi ! I has the same issue. To fix it I used condition thank’s to the context like that :

    public void Action(InputAction.CallbackContext context)
    {
        if (context.started)
        {
            Debug.Log("Action");
        }
    }

Since this thread came up high on Google, another solution is to run both action maps at once instead of switching. You can do either:

  1. Code - https://youtu.be/NZBAr_V7r0M?t=166 -
    FindActionMap(“Name1”).Enable; FindActionMap(“Name2”).Enable;
  2. Making a second input action asset. no additional code needed. Changing Action Maps with Unity's "New" Input System — One Wheel Studio - 2 input assets, one for the Player and one for Ui, each with their own action maps. So in essence you can switch action maps on each as needed with the manager but having 2 input assets means that Ui messages are broadcast all the time, which eliminates most of the problems :slight_smile: