NullReferenceException after passing InputField gameObject into EventSystem.SetSelectedGameObject()

For some reason InputManager settings are ignored, so I’ve implemented a script to navigate UI elements. There’s an idea:

Selectable current

void setCurrent(Selectable selectable) {
      current = selectable;
      EventSystem.current.SetSelectedGameObject(current.gameObject, null);
}

void Update(){
      if(current == null) {
          setCurrent(Selectable.allSelectables[0]);
      }

      if(Input.GetKeyDown(KeyCode.UpArrow) && current.navigation.selectOnUp != null) {
          setCurrent(current.navigation.selectOnUp);
     }
}

It works when current contains Buttons or Toggles, but when it is InpuField navigation breaks and log gives me following error every frame.

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.UI.InputField.ActivateInputFieldInternal () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/InputField.cs:2213)
UnityEngine.UI.InputField.LateUpdate () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/InputField.cs:725)

Hello,

I had the same problem. I found out that in my case the currentInputModule (Unity - Scripting API: EventSystems.EventSystem.currentInputModule) of my current EventSystem (Unity - Scripting API: EventSystems.EventSystem.current) was null.