Search Unity

Errors with new input system when exiting play mode [SOLVED]

Discussion in 'Input System' started by kiamvdd, Feb 20, 2019.

  1. kiamvdd

    kiamvdd

    Joined:
    Sep 30, 2016
    Posts:
    16
    I've just started playing around with the new system today so this might be a silly oversight, but I'm getting a couple of errors after exiting playmode.

    I've hooked up two action maps, one for the player and another for the camera. The player just uses arrow keys / wasd and this works fine. For the camera I've set up a single binding for delta [Mouse]. This works in play mode and I can move the camera by hooking up a Move() method to performed. After exiting playmode however, I get four errors whenever I move the mouse. I've put them at the bottom of the post to avoid cluttering with a wall of text.

    Here's the callback related code:

    Code (CSharp):
    1.     private void Awake()
    2.     {
    3.        m_controls.Camera.Enable();
    4.        m_controls.Camera.Move.performed += Move;
    5.     }
    6.  
    7.     private void OnDestroy()
    8.     {
    9.        m_controls.Camera.Move.performed -= Move;
    10.     }
    11.  
    12.     private void Move(InputAction.CallbackContext ctx) { ... }
    13.  
    14.  
    This is the same way the player controls are set up, so I'm not sure what the problem is here. Am I doing something wrong with the setup here?



    Unity errors:
    _______________________________________________________________

    Code (CSharp):
    1. Map index out of range
    2. UnityEngine.Experimental.Input.LowLevel.<>c__DisplayClass8_0:<set_onBeforeUpdate>b__0(NativeInputUpdateType)
    3. UnityEngineInternal.Input.NativeInputSystem:NotifyBeforeUpdate(NativeInputUpdateType) (at C:/buildslave/unity/build/Modules/Input/Private/Input.cs:83)
    _______________________________________________________________

    Code (CSharp):
    1. Control index out of range
    2. UnityEngine.Experimental.Input.LowLevel.<>c__DisplayClass8_0:<set_onBeforeUpdate>b__0(NativeInputUpdateType)
    3. UnityEngineInternal.Input.NativeInputSystem:NotifyBeforeUpdate(NativeInputUpdateType) (at C:/buildslave/unity/build/Modules/Input/Private/Input.cs:83)
    _______________________________________________________________

    Code (CSharp):
    1. Binding index out of range
    2. UnityEngine.Experimental.Input.LowLevel.<>c__DisplayClass8_0:<set_onBeforeUpdate>b__0(NativeInputUpdateType)
    3. UnityEngineInternal.Input.NativeInputSystem:NotifyBeforeUpdate(NativeInputUpdateType) (at C:/buildslave/unity/build/Modules/Input/Private/Input.cs:83)
    _______________________________________________________________

    Code (csharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEngine.Experimental.Input.InputActionState+BindingState.get_actionIndex () (at Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs:2356)
    3. UnityEngine.Experimental.Input.InputActionState.ProcessControlStateChange (System.Int32 mapIndex, System.Int32 controlIndex, System.Int32 bindingIndex, System.Double time, UnityEngine.Experimental.Input.LowLevel.InputEventPtr eventPtr) (at Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs:949)
    4. UnityEngine.Experimental.Input.InputActionState.UnityEngine.Experimental.Input.LowLevel.IInputStateChangeMonitor.NotifyControlStateChanged (UnityEngine.Experimental.Input.InputControl control, System.Double time, UnityEngine.Experimental.Input.LowLevel.InputEventPtr eventPtr, System.Int64 mapControlAndBindingIndex) (at Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs:894)
    _______________________________________________________________
     
  2. kiamvdd

    kiamvdd

    Joined:
    Sep 30, 2016
    Posts:
    16
    After getting a good night's sleep, I took another look at what I was doing and I figured out my issue.
    I just had to make sure the controls get disabled when exiting play mode to prevent the input system being triggered unintentionally.

    The line that fixed the issue (placed in OnDestroy()):

    Code (CSharp):
    1.        m_controls.Camera.Disable();
    I will probably move this into an input manager at some point to make managing input maps easier, but for now this works. Problem solved!
     
    mkandersson and SeoFernando like this.
  3. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    @rkketchup Thank you for the report and for digging into this more deeply!

    The system has code to automatically disable all actions that are still enabled when exiting play mode but it looks like it's not working correctly at all times. I'll take a look at that. Filed a ticket here.
     
  4. MaxLohMusic

    MaxLohMusic

    Joined:
    Jan 17, 2022
    Posts:
    67
    After encountering this same error message with an entirely different cause, I finally figured out the workaround: Restart Unity. I *think* the cause was I saved Player's Input while the editor was in play mode.
     
  5. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    235
    Error persists in 2023.1.18f