I’m using the WebGL build on unity for my Convai-powered project, which I intend to make mobile-friendly. To facilitate interaction, I added a button that allows users to talk, and this functionality works fine. However, an issue arises when users prefer to type rather than talk. When they click on the TMP Input Field to type their message, the virtual keypad does not appear on mobile devices, making it impossible for users to type their input.
I’ve attempted to address this by manually triggering the virtual keyboard when the input field is selected, using TouchScreenKeyboard.Open. I added an onSelect listener for the TMP Input Field in the ‘ChatUI’ script, but it doesn’t seem to work in the WebGL build. Here’s the relevant code snippet:
Despite the code implementation, the keypad either fails to show when the input field is selected or shows but is completely unattached, meaning when I type on it nothing comes up in the text input field. Does anyone have insights into why this might be happening in the WebGL build, or suggestions for alternative approaches to ensure mobile users can type their input?
You’re experiencing with the virtual keyboard not appearing or being unresponsive when trying to type in the TMP Input Field on WebGL in Unity is not uncommon. Here’s a detailed breakdown of what might be happening and some potential solutions:
The default InputField component (not TMP) might work better in WebGL when trying to bring up the mobile virtual keyboard. While TMP is powerful, it might not always behave as expected in WebGL builds. If your project can afford a switch, consider testing the default InputField for the mobile WebGL build.
To implement this, try replacing the TMP Input Field with the regular Unity InputField component for WebGL: _inputField = UIInstance.transform.Find(“Panel/InputField”).GetComponent<UnityEngine.UI.InputField>();
2. Use HTML5/JS to Trigger the Mobile Keyboard (for WebGL)
Since WebGL runs in a browser, you might want to use JavaScript to handle the virtual keyboard on mobile devices. Unity allows you to call JavaScript code from C# in WebGL using Application.ExternalCall or Application.ExternalEval. This could be a way to open the browser’s native virtual keyboard.
Then, you would need to define the openVirtualKeyboard function in JavaScript on the web page hosting your Unity WebGL build. This function would trigger the mobile virtual keyboard.