As you can see on screenshots, Apple’s keyboard does not show input field on initial launch.
This bug disappears after relaunch.
My Unity version is 4.6.4f1 and text input is implemented by NGUI UIInput.
If you are still seeing this on a recent Unity version, please file a bug and attach the project to it. Please paste the bug id here. Thanks ![]()
I can confirm this bug is still happening in Unity 5.1.2 on iOS. I did not test android. It works fine in the editor because there is no mobile keyboard widget.
I tracked it down and here’s what seems to be happening:
Test Scene:
Create a simple scene with 2 input fields InputField_0 and InputField_1
Bug Repeat Case:
- Tap on InputField_0. The iOS keyboard comes up.
- BUG: Tap QUICKLY on InputField_1, the keyboard diappears and nothing has focus.
Success Case:
- Tap on InputField_0. The iOS keyboard comes up.
- Tap on InputField_1 and HOLD YOUR FINGER there until the keyboard fully disappears.
Assessment:
It appears as if you fully need to wait for they keybaord to disappear before letting go of InputFiled_1 in order for the focus request to register. Otherwise, the closing of the mobile keyboard from the InpuField_0 will call the OnEndEdit() event for InputFiled_1
Ideal Solution:
Ideally switching between input fields would just keep the keyboard visible like it does on native implementations.
Debug Info:
Here is the call stack from the Unity generated XCode project for what is happening.
I tap on InputField_0 and get this
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
TableItem:OnClickCallback() (at /Users/mike/src/aj/hmm/Assets/TableItem.cs:37) //
UnityEngine.Events.InvokableCall:Invoke(Object[ ])
UnityEngine.Events.InvokableCallList:Invoke(Object[ ])
UnityEngine.Events.UnityEventBase:Invoke(Object[ ])
UnityEngine.Events.UnityEvent:Invoke()
UnityEngine.UI.ButtonPress()
UnityEngine.UI.Button:OnPointerClick(PointerEventData)
UnityEngine.EventSystems.ExecuteEvents:Execute(IPointerClickHandler, BaseEventData)
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
UnityEngine.EventSystems.TouchInputModuleProcessTouchPress(PointerEventData, Boolean, Boolean)
UnityEngine.EventSystems.TouchInputModuleProcessTouchEvents()
UnityEngine.EventSystems.TouchInputModuleProcess()
UnityEngine.EventSystems.EventSystem:Update()
(Filename: /Users/mike/src/aj/hmm/Assets/TableItem.cs Line: 37)
I now tap on InputField_1 which takes focus away from InputField_0 and starts hiding the keyboard.
TableItem:OnEndEditHandler() (at /Users/mike/src/aj/hmm/Assets/TableItem.cs:70)
UnityEngine.Events.InvokableCall:Invoke(Object[ ])
UnityEngine.Events.InvokableCallList:Invoke(Object[ ])
UnityEngine.Events.UnityEventBase:Invoke(Object[ ])
UnityEngine.Events.UnityEvent1:Invoke(T0) UnityEngine.UI.InputField:SendOnSubmit() UnityEngine.UI.InputFieldDeactivateInputField() UnityEngine.UI.InputField:OnDeselect(BaseEventData) UnityEngine.EventSystems.ExecuteEvents:Execute(IDeselectHandler, BaseEventData) UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction1)
UnityEngine.EventSystems.EventSystem:SetSelectedGameObject(GameObject, BaseEventData)
UnityEngine.EventSystems.PointerInputModuleDeselectIfSelectionChanged(GameObject, BaseEventData)
UnityEngine.EventSystems.TouchInputModuleProcessTouchPress(PointerEventData, Boolean, Boolean)
UnityEngine.EventSystems.TouchInputModuleProcessTouchEvents()
UnityEngine.EventSystems.TouchInputModuleProcess()
UnityEngine.EventSystems.EventSystem:Update()
… that same click give focus to InputField_1 (note keyboard is still moving to hidden position)
TableItem:OnClickCallback() (at /Users/mike/src/aj/hmm/Assets/TableItem.cs:37)
UnityEngine.Events.InvokableCall:Invoke(Object[ ])
UnityEngine.Events.InvokableCallList:Invoke(Object[ ])
UnityEngine.Events.UnityEventBase:Invoke(Object[ ])
UnityEngine.Events.UnityEvent:Invoke()
UnityEngine.UI.ButtonPress()
UnityEngine.UI.Button:OnPointerClick(PointerEventData)
UnityEngine.EventSystems.ExecuteEvents:Execute(IPointerClickHandler, BaseEventData)
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
UnityEngine.EventSystems.TouchInputModuleProcessTouchPress(PointerEventData, Boolean, Boolean)
UnityEngine.EventSystems.TouchInputModuleProcessTouchEvents()
UnityEngine.EventSystems.TouchInputModuleProcess()
UnityEngine.EventSystems.EventSystem:Update()
HERE IS THE BUG – As soon as the mobile keyboard slides off screen to its hidden position, this call stack calls the OnEndEdit() event for InputField_1, taking focus away from InputField_1 and leaving nothing with foucs.
TableItem:OnEndEditHandler() (at /Users/mike/src/aj/hmm/Assets/TableItem.cs:70)
UnityEngine.Events.InvokableCall:Invoke(Object[ ])
UnityEngine.Events.InvokableCallList:Invoke(Object[ ])
UnityEngine.Events.UnityEventBase:Invoke(Object[ ])
UnityEngine.Events.UnityEvent`1:Invoke(T0)
UnityEngine.UI.InputField:SendOnSubmit()
UnityEngine.UI.InputFieldDeactivateInputField()
UnityEngine.UI.InputField:OnDeselect(BaseEventData)
UnityEngine.UI.InputField:LateUpdate()
I submitted a bug, it is Case 718407

