[WebGL] UI Toolkit Touch Input Failure Resolved for Mobile Browsers
Solution
Unity 2021.3.x - Unity 6.3.x
Published Thu, Mar 19
UI Toolkit buttons and ListView elements exhibit inconsistent and erratic behavior with touch input when a WebGL build is accessed via a mobile browser. Touch presses often fail to register as clicks, requiring multiple attempts or specific gestures like holding and moving the finger. This issue is specific to touch input on mobile WebGL, as mouse input on PC browsers functions correctly. This behavior differs from the legacy UI system, where touch inputs were handled natively without extra configuration.
Ensure an EventSystem and an InputSystemUIInputModule are present in the scene. Configure the Pointer Behavior to Single Unified Pointer to resolve inconsistent touch input for UI Toolkit elements in WebGL mobile builds.
The root cause of inconsistent touch input for UI Toolkit elements on WebGL mobile builds is the absence of a properly configured EventSystem and an InputSystemUIInputModule. Reliable touch interactions necessitate the presence of these dedicated event processing components and a specific Pointer Behavior configuration.
- Open your scene and create a new
EventSystemby selecting GameObject > UI > Event System. - In the Inspector, ensure the
InputSystemUIInputModulecomponent is attached to theEventSystemobject. - Locate the Pointer Behavior property within the
InputSystemUIInputModulesettings. - Change the value of Pointer Behavior to Single Unified Pointer.
- Ensure your
UIDocumentpanel settings are configured to receive events from theEventSystem.
Additional Tips
- Use CSS
touch-action: nonein yourWebGLtemplate to prevent the browser from capturing gestures. - Test your build in a private browser window to ensure that cached input scripts are not causing conflicts.
- Verify that the Pointer Behavior is set globally if you use multiple scenes with separate
EventSystemobjects.
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
Content inspired by a Unity discussion post.