[SOLVED] Input System: Second Action Map beeing ignored

Hello everyone,

So, I am using the new input system, and I have one InputActions asset with two Action Maps.
The first action map (Figure 1) works properly, but the second one (Figure 2) gets ignored when I change to it.

My player has a PlayerInput component, and some code to move around in response to the commands.
I am currently using the following code to test the change in Action Map:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class ChangeActionMap : MonoBehaviour
{
    // TESTING CONTROL SCHEME CHANGE
    PlayerInput playerInput;
    // Start is called before the first frame update
    void Start()
    {
        playerInput = GetComponent<PlayerInput>();
    }
    // Update is called once per frame
    void Update()
    {
        var _keyboard = Keyboard.current;
        if (_keyboard.nKey.wasPressedThisFrame)
        {
            playerInput.SwitchCurrentActionMap("Gameplay2");
            Debug.Log(playerInput.currentActionMap.ToString());
        }
        if (_keyboard.mKey.wasPressedThisFrame)
        {
            playerInput.SwitchCurrentActionMap("Gameplay");
            Debug.Log(playerInput.currentActionMap.ToString());
        }     
    }
}

So when I press “n”, PlayerInput changes to the second action maps, and no command moves the player. I get no error messages. And when I press “m”, controls work again.

Has anyone experienced such a problem, or can identify the error?

Thanks in avance!!


It looks like you have two action maps that both define a “Move” action. Because they are in different maps - even though they have the same name, they actually produce two distinct InputActions (which each have their own callbacks!)

How are you reading/polling/listening to the Inputs? With PlayerInput SendMessage, Unity Events, C# Events, or manually through the InputActionAsset?

Yess!! This solved my problem!! Thank you so much!
I was reading the values with the following code (for Move, as an example):

playerInput.actions.FindAction("Move").performed += ctx => i_movement = ctx.ReadValue<Vector2>();
playerInput.actions.FindAction("Move").canceled += ctx => i_movement = Vector2.zero;

I assumed that changing the Action Map would make this “FindAction()” to automatically search on the current action map, but apparantly it found the one on the first ActionMap, then ignored it for not beeing the active one.
So giving my actions different names, and telling the code to listen to all of them did the trick.

I was struggling with this for days already. Thanks again for the help!

1 Like

Nice! :slight_smile: Glad to help heh.

Also the “Gamepad and Keyboard Simultaneous Support” is kinda what Control Schemes are for.

Additionally it looks like you’re trying to split the keyboard into a Left Half Right Half type thing.

If thats the case - take a look at this thread / utility I kicked out the other day heh - will save you a lot of pain with PlayerInput.

@Rene-Damm
Does it make sense to allow same-name InputActions existing seeing as FindAction and the [actionName] indexer exist? Seems weird to have a dictionary-like indexer without guaranteed unique indexes. Maybe a LogWarning at least in the editor when you try to FindAction and it sees more than one valid hit?

2 Likes