- Home /
How do I disable player input action map and enable the UI action map?
New input system 1.0.0 I am using the player input component with the behavior set to invoke unity events set. I have a player input action map and a UI action map. When the player brings up any UI i want to disable the player action map and enable the UI action map. I don't want the player to be able to move around wall using UI. I did this in the old input system but with the new input system and unity events im lost.
Can i do this if i am using the player input component with unity events? if so are there any good resources and or suggestions?
Thanks
Answer by devinallen1 · Feb 11, 2020 at 06:19 AM
I figured it out. I needed to be using UnityEngine.InputSystem as a using statment. Doing this gave me access to the player input current action map and i could then call .Disable()
I tried this however it did not work... What exactly did you do? Can you share a code snippet?
So this is the top google result for how to disable input action maps, and you mention the solution, but don't have the syntax. I've searched everywhere for this dang syntax and everyone skips it as obvious... Any chance you could share it for us?
Encountering this myself just now and co$$anonymous$$g onto this answer first.. Here is the actual answer for those after me..
Get the player input component
PlayerInput input = GetComponent<PlayerInput>(); input.actions.Disable();
Access the
actions
object and disabled/enable it
input.actions.Disable();
All together: GetComponent<PlayerInput>().actions.Disable();
I also have this problem. I'm trying to switch the action map from Player to UI whenever I press the pause button but it's not working. I don't know what the problem is. Should I use something else instead of actions
? Any suggestions? This is my pause menu code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PauseMenu : MonoBehaviour
{
public static bool GameIsPaused = false;
public GameObject pauseMenuUI;
public void PauseInput(InputAction.CallbackContext context)
{
if (GameIsPaused)
{
Resume();
}
else
{
Pause();
}
}
public void Resume()
{
Player.Instance.GetComponent<PlayerInput>().actions.Enable();
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
GameIsPaused = false;
}
public void Pause ()
{
Player.Instance.GetComponent<PlayerInput>().actions.Disable();
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
GameIsPaused = true;
}
}
Answer by Gawidev · May 22, 2021 at 11:09 PM
Allright, since this is still the #1 link in google search for this I'll add that the most likely way to run into this issue is trying to disable the action map from another script/object not realizing each instance has its own copy of the Input Actions. Hope this helps.
Thanks for this!
I have been banging my head against walls 8 hours trying to update my Input Actions on the fly through code. Seems, with what you've said, I've been looking in the wrong place to verify my changes all along. I must have missed this in the documentation somewhere. ;)
Answer by Bmarlyman21 · Nov 10, 2021 at 01:45 PM
If you set a public static Input Action variable in one script and have all others access only that one, then you can enable and disable it without issues.
I am a little new to the input system, so this may not be the best solution, but it has worked for me so far.
Answer by Saucyminator · May 29 at 06:37 PM
I think you can use PlayerInput.SwitchCurrentActionMap or swiching to another action map, here's the docs.
Your answer
Follow this Question
Related Questions
How can I translate my arrow keys input to my controller joystick? 0 Answers
Hover Over Input Field Before Inputting? 2 Answers
How to change a float value with UI buttons,How Can I control a character with UI buttons? 1 Answer
Link UI Input Field to Script 2 Answers
Help Needed: How to Use Input Manager on UI Button 0 Answers