What I’m trying to achieve is to enable only the corresponding ActionMap based on the state of the game, and disable all other ActionMaps, what is the right way to do it?
According to the documentation and the discussion I googled, PlayerInput can only have one enabled ActionMap at a time.
To my understanding, only Actions in the enabled ActionMap can trigger Performed events in response to user input.
If that’s not the case, then I’m totally confused.
Here is the actual situation I encountered:
[RequireComponent(typeof(PlayerInput))]
public class InputLogger : MonoBehaviour
{
private PlayerInput _pInput;
public PlayerInput PInput => _pInput ??= gameObject.GetComponent();
void Start()
{
// both Jump and Sumbit are binding with buttonSouth[Gamepad]/ Enter[Keyboard]
PInput.actions.FindAction("Test").performed += c => { Debug.Log("Test"); };
PInput.actions.FindAction("Submit").performed += c => { Debug.Log("Submit"); };
foreach (var map in PInput.actions.actionMaps)
{
Debug.Log($"{map.name} {map.enabled}");
}
PInput.SwitchCurrentActionMap("UI");
PInput.SwitchCurrentActionMap("Player");
foreach (var map in PInput.actions.actionMaps)
{
Debug.Log($"{map.name} {map.enabled}");
}
}
}
Click Play
-
The DefaultActionMap of PlayerInput is “Player”, but the log shows that both “Player” and “UI” are enabled at the beginning.
(I remember in a previous discussion, someone encountered the same problem, and the reason was related to PlayerInput referencing EventSystem, but in my case there is no EventSystem.) -
On Start(), the ActionMap “UI” is already disabled, but Action “Submit” is still able to trigger Performed.
PS. I’ve tried the recommended Action workflow, but our game needs to support local multiplayer, and according to the docs, I should use PlayerInput.