Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Action getting called from another action map

Discussion in 'Input System' started by Jichaels, Oct 14, 2019.

  1. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    Hey,

    I'm using PlayerInput and the new version of the IS (1 preview) and I noticed a weird behaviour. I don't know if it happened before because I just implemented it.

    Basically, I'm using an InputAction file with two control scheme (Gamepad/Mouse&Keyboard), and two action map, "Player" for the gameplay and "UI" for UI (I'm trying to do all navigation myself because there is weird things happening when switching between devices). I'm using the Invoke Unity event in player input.

    The problem is, action from my UI action map are getting called when I'm on the Player action map. Isn't PlayerInput supposed to restrict to only the active ActionMap ?
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    PlayerInput will only activate one map at a time by default but it won't prevent other pieces of code from enabling or disabling actions of their own.

    In this case, it's the UI input module doing its own thing. It will enable the actions it is assigned when is it itself enabled and disable them when disabled.
     
  3. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    Mmmh, I don't think it's what's happening here. On my PlayerInput, I've bound all my actions to callbacks in my player script like so
    Code (CSharp):
    1. public void OnAttack1(InputAction.CallbackContext ctx)
    2.     {
    3.         if (!ctx.performed) return;
    4.         _primaryAction = Mathf.Approximately(ctx.ReadValue<float>(), 1);
    5.     }
    But callbacks of action within my "UI" action map are getting called even if I'm on the "Player" actionmap.

    I'm using another input action asset file for the UI Input module, because it's not working with the same one ( it's a known bug apparently, you replied here : https://forum.unity.com/threads/but...input-system-ui-input-module-in-scene.748757/ ).

    Maybe I'm doing something wrong, but I can't find why. :(
     
  4. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    I've no clue if that's related or not, but there is a REALLY weird thing going on. I have callbacks thare are getting called from a script that is on a monobehaviour of ANOTHER scene, what the heck ?

    In my second scene I've a gameObject with "CharacterSelection" script attached to it, I've an InputActionReference navigationReference that I use like this

    Code (CSharp):
    1. [SerializeField] private InputActionReference navigationReference;
    2.  
    3. private void Awake()
    4. {
    5.     navigationReference.action.performed += OnNavigate;
    6. }
    7.  
    8. private void OnNavigate(InputAction.CallbackContext ctx)
    9. {
    10.     Debug.Log(ctx, this);
    11.     if (!ctx.performed) return;
    12. }
    And it's getting called when I go to the next scene (basic LoadScene, not additive or anything). And it's still printing ?!


    EDIT : So if you don't unregister the event, it can be called even if there is no gameobject/script on the scene. Definitely looks like a bug to me, right ?
     
  5. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    InputActions have no concept of scenes. So yes, as long as an action remains enabled, it will trigger.

    PlayerInput integrates this with the GameObject world and will disable its actions once it is itself disabled (e.g. when going to another scene) but when working with actions directly, it's basically up to you to enable and disable actions as needed.
     
  6. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    Wow ok, that's weird to me, but if it's normal then fine I'll deal with this.

    Any idea about the ActionMap thing though ? I may just wait before dealing with all UI stuff, I've tons of things to do anyway
     
  7. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    What's the input debugger saying? Are the UI actions enabled?
     
  8. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    I changed a lot since then and I can't reproduce anymore, sorry :(

    Maybe registering the input action set it to activated by default ?

    My bad anyway, I'm still a bit confused about all ways of doing thing (and even more now that I mix them in the same project :D)
     
  9. kukurenaiz

    kukurenaiz

    Joined:
    Sep 12, 2017
    Posts:
    57
    I'm having to deal with a very similar situation, I have two action maps, UI and Player, everything works fine at first, the default action map is set to Player. When I turn my inventory on, I switch to the UI action map with the
    Code (CSharp):
    1. playerInput.SwitchCurrentActionMap("UI");
    , but when I switch back to the Player action map, the actions mapped with the same bindings as my UI (e.g., dpad for walk in the player, and the same dpad for navigation in the UI) throws a Should Not Get Here Exception
    Code (CSharp):
    1. Should not get here
    2. UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*) (at ?)
    3. UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr) (at C:/buildslave/unity/build/Modules/Input/Private/Input.cs:120)
     
  10. ThePilgrim

    ThePilgrim

    Joined:
    Apr 25, 2013
    Posts:
    18
    I ran into a similar problem. In my case, two actions in two separate action maps were being triggered by a single key press if the following criteria were met:

    1. Two action maps exist, each one containing an action that is bound to the same key.
    2. In the second action map, a one modifier composite action exists with a main binding to the same key as the other two actions.
    3. Upon receiving an action triggered event (from PlayerInput.onActionTriggered), switch from the first action map to the second.

    In this situation, when I received the input from the first action map and immediately switched to the second action map, the action bound to the same key on the second action map was also triggered. When I removed the composite action or changed its binding so that it was a different key than the other two actions, the problem no longer occurred.

    I have sent a bug report with a repro project.

    Edit: Here is a link to the tracked issue: https://issuetracker.unity3d.com/is...-another-similar-but-composite-binding-exists
     
    Last edited: Dec 15, 2023