Search Unity

[SOLVED] error while switching between action maps

Discussion in 'Input System' started by kukurenaiz, Feb 9, 2020.

  1. kukurenaiz

    kukurenaiz

    Joined:
    Sep 12, 2017
    Posts:
    57
    Good night, I want to understand how the workflow of action maps work, from my understanding after some time reading was that: You define contexts for your input, one for the inventory and another for controlling the player for example, I understand that (everything's changing so fast), but I can't get it to work.

    When I change from the Player action map to the UI action map with

    Code (CSharp):
    1.  playerInput.SwitchCurrentActionMap ("UI");
    2.  
    Everything works fine, it doesn't call any actions from the Player map anymore, but when I switch back and call an action with the same binding as my UI (e.g., dpad for moving the player, and the same dpad for navigating on the UI, in a different action map), it throws a Should Not Get Here exception, but the player actions are working normally.

    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)
    Am I misunderstanding something?
     
    Last edited: Feb 14, 2020
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Is this with 1.0.0-preview.4? I was under the impression this one got fixed.
     
  3. kukurenaiz

    kukurenaiz

    Joined:
    Sep 12, 2017
    Posts:
    57
    yes, sorry, I'm in 1.0.0-preview.4, I'll try to reproduce.
     
  4. Lightzer

    Lightzer

    Joined:
    Jun 23, 2018
    Posts:
    5
    I'm also running into errors when switching maps on 1.0.0 preview.4

    I'm get a "Control index is out of range" when switching from UI to Player using a PlayerInput component sending C# Events, and switching action maps in the same way as Yemnefer.

    I also get 5 "Should not get here" errors whenever I exit play mode.
     
  5. kukurenaiz

    kukurenaiz

    Joined:
    Sep 12, 2017
    Posts:
    57
    Here's the sample project, easily reproducible in a new Unity Project. (2019.2.19f1) (1.0.0-preview.4)

    With the sample project:
    1. Open the Sample Scene.
    2. Perform the Move Action (default: left stick), check the console.
    3. Perform the Start Action (default: start), the inventory opens and the action map is changed (Player > UI).
    3. Press start, the action map is changed again (UI > Player)
    4. Perform the Move Action (Should Not Get Here Exception is being thrown along with the logs), the Fire Action (a player map only) doesn't throw anything.

    In A new Unity Project
    1. In a new Unity project, Add a Player Input Component (not sure if the player input is part of the problem).
    2. Create an Input Action Asset and two actions maps.
    3. Give both action maps an action with same keybindings.
    4. Switch from the default map to the other, then switch back, Should Not Get Here here is being thrown when performing that action.
     

    Attached Files:

    Last edited: Feb 11, 2020
  6. JamhammerDev

    JamhammerDev

    Joined:
    Jul 11, 2015
    Posts:
    28
    Thought so too, but we have the error. Found this helped as a workaround.

    Code (CSharp):
    1. input.uiInputModule.enabled = false;
    2. input.uiInputModule.enabled = true;
     
    Lightzer likes this.
  7. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Thanks for the repro. Looking.
     
    Last edited: Feb 13, 2020
  8. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Fix in flight.

    Problem turned out to be that the code didn't properly deal with some piece of code enabling only specific actions and another enabling entire action maps. The former is done by InputSystemUIInputModule on the "UI" action map whereas the latter is done by PlayerInput.

    ////EDIT: Fix unfortunately didn't make it in time for 1.0.0-preview.5 (QA already concluded and fix is too intrusive to sneak it in) but will be in next package.
     
    Last edited: Feb 14, 2020
  9. CameronOtten

    CameronOtten

    Joined:
    Apr 1, 2015
    Posts:
    12
    Was running into this as well, this worked for me too, thanks
     
  10. kukurenaiz

    kukurenaiz

    Joined:
    Sep 12, 2017
    Posts:
    57
    Everything's working in 1.0.0-preview.6, thank you very much.
     
    Last edited: Mar 10, 2020
    Rene-Damm likes this.
  11. dCalle

    dCalle

    Joined:
    Dec 16, 2013
    Posts:
    55
    randomly pops up for me again with 1.0.0 final. logs the (potentially) error pausing 'control index out of range' error even earlier and every second time when using PlayerInput.actions.Disable()/Enable()
     
    Last edited: Oct 18, 2020
  12. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    There's a fix in the upcoming 1.1-preview.2 (due out this week) which might be the issue you're running into.
     
    dCalle likes this.