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

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:

    private void Awake()
    {
       m_controls.Camera.Enable();
       m_controls.Camera.Move.performed += Move;
    }

    private void OnDestroy()
    {
       m_controls.Camera.Move.performed -= Move;
    }

    private void Move(InputAction.CallbackContext ctx) { ... }

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:


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

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

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

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.Experimental.Input.InputActionState+BindingState.get_actionIndex () (at Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs:2356)
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)
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)

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()):

       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!

2 Likes

@kiamvdd 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.

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.

2 Likes

Error persists in 2023.1.18f

Yeah same happened to me