Hi,
I encounter the following problem in my project.
Depending on the states of the games, action maps should be activated/deactivated. Everything works fine but If an action triggers the deactivation of its own map and this map is reactivated later in the fame, the action is like stuck in an undefined state, so I need to push 2 times the button in order to trigger the action.
I made a simple example to illustrate this. It’s a very simple 2 states management system. The states can be switched by pushing buttons on the gamepad.
- I first created a new action map asset with 2 maps (map1 and map2)
- Then I use this only script to manage the states in the game:
using UnityEngine;
using UnityEngine.InputSystem;
public class stateManagement : MonoBehaviour, NewControls.IMap1Actions, NewControls.IMap2Actions
{
private NewControls controls;
public int state;
public void OnToState1(InputAction.CallbackContext context)
{
if(context.performed)
{
state = 1;
controls.map1.Enable();
controls.map2.Disable();
}
}
public void OnToState2(InputAction.CallbackContext context)
{
if(context.performed)
{
state = 2;
controls.map2.Enable();
controls.map1.Disable();
}
}
void Start()
{
controls = new NewControls();
controls.map1.SetCallbacks(this);
controls.map2.SetCallbacks(this);
state = 1;
controls.map1.Enable();
controls.map2.Disable();
}
}
-
The game starts in state 1. Then I trigger the “ToState2” (button A) action, the game switchs to state 2. Everything is fine.
-
Then I trigger the “ToState1” (button X) action, the game switchs to state 1. Still fine.
-
Then, if I push the button A again, the game doesnt switch to state 2. I need to push the button A a second time in order to achieve this.
Am I doing something wrong?
I’m using the Input System 1.0.0 preview 3. But I had this problem already in older versions
I tried to use “release only” interaction instead of “press only” and the problem of double taping is solved. But this is not the functionality I want. I want to be able to use “press only”.
It seems to be a bug. Some developers here to try to reproduce the error. (see my first post. It can be reproduced in 5min). Thanks for the support
OK, I made an official bug report. If I get information from the developer team I will add it there.
I just found a similar error which has been already communicated in April 19:
https://forum.unity.com/threads/bugs-action-map-ignores-keyboard-after-disabling-and-re-enabling-error-messages-on-reload.661492/
This issue is very critical because it just make the action map system unusable in many cases, which is one of the most important feature in the new input system in my opinion.
Some developers here to help?
Thanks!
I’m using a state machine in my game to handle different states in the enter function of each state i call the action map enable, and on the exit i call the disable function, I didn’t encounter this problem.
from going quickly over your code I would try Disabling the previous map before enabling the new one.
public void OnToState1(InputAction.CallbackContext context)
{
if(context.performed)
{
state = 1;
controls.map2.Disable(); // <---- changed this to be first
controls.map1.Enable();
}
}
public void OnToState2(InputAction.CallbackContext context)
{
if(context.performed)
{
state = 2;
controls.map1.Disable(); // <---- changed this to be first
controls.map2.Enable();
}
}
Thanks for your help. But it didn’t work
I use also in my game the enable/disable of maps. It works fine most of the time but not if you disable a map after pushing a button. The associated action is then like stuck in an undefined state. If you enable again this action map later, the action is not triggered on the first time but only on the second time.
a few days after I have posted here I encountered the same problem in my project, my escape key was mapped in 2 action maps to a “Cancel” action, and when I was trying to get out of menus I needed to press it twice to get it to work,
I found that I had an old piece of code enabling the input actions, so effectively I enabled them twice, once I removed the old redundant code every thing worked fine.
I’m also using a different syntax to get the key press, like this
InputActions.MyMap.MyAction.performed += ctx => MyFunction();
maybe try removing the enable from the start method, and from any other script. try to enable it only once
using UnityEngine;
using UnityEngine.InputSystem;
public class stateManagement : MonoBehaviour, NewControls.IMap1Actions, NewControls.IMap2Actions
{
private NewControls controls;
public int state;
public void OnToState1(InputAction.CallbackContext context)
{
if(context.performed)
{
state = 1;
controls.map1.Enable();
controls.map2.Disable();
}
}
public void OnToState2(InputAction.CallbackContext context)
{
if(context.performed)
{
state = 2;
controls.map2.Enable();
controls.map1.Disable();
}
}
void Start()
controls.map1.SetCallbacks(this)
controls.map2.SetCallbacks(this);
controls = new NewControls();
state = 1;
}
}
I posted this reply in another thread too, but I decided to post here as well as it will probably help you get this working :
Had the same issue using TAB-Key.
Then I switched the Interaction on that Action to “Release Only” and it started working.
Seems the preliminary analysis of others in this thread is correctly : if you call SwitchCurrentActionMap() during the Completed-phase of a “Press Only” Interaction, the control-state becomes unstable.
This issue has been solved in the 1.0.0-preview 6. Thanks!!