Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Discussion Unity WebGL on Mobile Devices

Discussion in 'Web' started by ronchito, Feb 18, 2023.

  1. ronchito

    ronchito

    Joined:
    Dec 4, 2013
    Posts:
    14
    I am aware of the following statement at the official Unity WebGL documentation, but still wonder about it:

    "Unity WebGL doesn’t support mobile devices. It might work on high-end devices, but current devices are often not powerful enough and don’t have enough memory to support Unity WebGL content."

    This statement appeared in the documentation of Unity 5.3 (and is still there in Unity 2023), and I'm sure that browsers and mobile devices evolved a lot during these ~8 years.

    But, I see that some games (made in Unity WebGL) do work properly in (various) browsers on android and iOS.
    My app (I'm using the devices camera and ML modules) works well on old Android devices (4 years old) but doesn't work on newer Android devices and the newest iPhones, and iPads at all.

    1. How come old android phones are „more powerful“ than the latest iOS devices?
    2. Are there any specific known limitations (packages) that couldn't work on some mobile devices?
    3. Does Unity plan to officially support WebGL on mobile devices in the future?
     
    Last edited: Feb 20, 2023
    makaka-org likes this.
  2. arjuniscool0204

    arjuniscool0204

    Joined:
    May 16, 2017
    Posts:
    14
  3. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,132
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,467
    Those device are not „more powerful“ just because newer Apple devices won‘t run the app. It just tells you that you have a broken iOS build and you need to debug what the cause of that is. Check console logs. It may be an incompatibility with Safari/Webkit, a violation of terms enforced by iOS, trying to use a feature that is not or no longer supported on iOS.
     
  5. menguzar

    menguzar

    Joined:
    Jan 31, 2022
    Posts:
    10
    why can't unity use an established framework like three or babylon to export webgl content? or, barring that, create a web-native framework for its player?

    the capabilities and limitations seem about the same with unity's webgl player, but they DO work on mobile, and are quite performant too.

    Unity's problem with WebGL builds seem to lie mainly in the player itself.

    I'd like to find out what people think about this.
     
  6. unityruba

    unityruba

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    278
    The reason is because we're offering people the capabilities of the Unity engine, which can do *a lot*, and we're converting that to something that can run in a web browser. That has a cost, of course. It works for some use cases, but not others, which would benefit from using something like three.js and such.
     
    makaka-org likes this.
  7. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    1,055
    I tested with Unity 2022.3.7, iPhone XS Max, Samsung Galaxy A71. WebGL works.
    Moreover, the New Input System declares here that sensor (accelerometer, gyro, etc.) support for WebGL on Android and iOS devices is available in Unity 2021.2.

    So it works, and I recorded a video tutorial about building and testing for Mobile WebGL.

    > Complete Article with all Links and Commands <

     
  8. ashfaqueck

    ashfaqueck

    Joined:
    Jan 25, 2017
    Posts:
    9
    Hey there,
    I was trying to get the URP sample running on the mobile webGL. Everything works fine except the device type. The scene does this in code



    Code (CSharp):
    1. if (SystemInfo.deviceType == DeviceType.Handheld)
    2. {
    3.      m_TouchInputCanvas.SetActive(true);
    4. }
    This is fine on web since its keyboard controls. But for mobile there is a dedicated touch control UI which is not getting activated from the above code. Is this the same mechanism to identify device type on a mobile browser? I mean will this differentiate a browser as it is on a desktop OR mobile?
     
    Last edited: May 6, 2024
  9. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    1,055
    There was an issue with this or with compiler directives, I don't remember exactly, but I found a solution such way. In my Sensor Camera (Unity Asset) I use the next boolean flags:

    Code (CSharp):
    1. isWebGLOnDesktop = !Application.isMobilePlatform
    2.     && Application.platform == RuntimePlatform.WebGLPlayer;
    3.  
    4. isWebGLOnMobile = Application.isMobilePlatform
    5.     && Application.platform == RuntimePlatform.WebGLPlayer;
     
  10. ashfaqueck

    ashfaqueck

    Joined:
    Jan 25, 2017
    Posts:
    9


    Thanks for the response buddy.

    BTW I solved it by getting back that info from the browser end using jslib communication.

    I used this function there on the jslib file

    Code (JavaScript):
    1. isHandHeldDevice: function () {
    2.      if (navigator.userAgent.match(/Android/i)
    3.          || navigator.userAgent.match(/webOS/i)
    4.          || navigator.userAgent.match(/iPhone/i)
    5.          || navigator.userAgent.match(/iPad/i)
    6.          || navigator.userAgent.match(/iPod/i)
    7.          || navigator.userAgent.match(/BlackBerry/i)
    8.          || navigator.userAgent.match(/Windows Phone/i)) {
    9.             return  true ;
    10.          } else {
    11.             return  false ;
    12.          }
    13.   },
    Now I have it working with appropriate platform specific controls.
     
  11. ashfaqueck

    ashfaqueck

    Joined:
    Jan 25, 2017
    Posts:
    9
  12. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    1,055
  13. ashfaqueck

    ashfaqueck

    Joined:
    Jan 25, 2017
    Posts:
    9

    That helped. Thanks buddy. Will host it somewhere soon and let you know.
     
  14. ashfaqueck

    ashfaqueck

    Joined:
    Jan 25, 2017
    Posts:
    9


    The build runs fine on android. But not on iOS,

    Are there some limitation for unity WebGL on iphone?

    Device : iphone 14
    Cache disabled
    Uncompressed
    ASTC Texture compression





    Attached is the log. After this the unity loaded restarts. Literally the progress bar starts again from beginning. After some attempts it shows "Can't open this page"

    @unityruba @makaka-org





    Code (CSharp):
    1.  
    2.  
    3. ERROR still waiting on run dependencies:
    4. ERROR dependency: wasm-instantiate
    5. ERROR (end of list)
    6. ERROR still waiting on run dependencies:
    7. ERROR dependency: dataUrl
    8. ERROR (end of list)
    9.  
    10. LOG[UnityMemory] Configuration Parameters - Can be set up in boot.config
    11. LOG    "memorysetup-allocator-temp-initial-block-size-main=262144"
    12. LOG    "memorysetup-allocator-temp-initial-block-size-worker=262144"
    13. LOG    "memorysetup-temp-allocator-size-audio-worker=65536"
    14. LOG    "memorysetup-temp-allocator-size-background-worker=32768"
    15. LOG    "memorysetup-bucket-allocator-granularity=16"
    16. LOG    "memorysetup-bucket-allocator-bucket-count=8"
    17. LOG    "memorysetup-bucket-allocator-block-size=4194304"
    18. LOG    "memorysetup-bucket-allocator-block-count=1"
    19. LOG    "memorysetup-main-allocator-block-size=16777216"
    20. LOG    "memorysetup-thread-allocator-block-size=16777216"
    21. LOG    "memorysetup-gfx-main-allocator-block-size=16777216"
    22. LOG    "memorysetup-gfx-thread-allocator-block-size=16777216"
    23. LOG    "memorysetup-cache-allocator-block-size=4194304"
    24. LOG    "memorysetup-typetree-allocator-block-size=2097152"
    25. LOG    "memorysetup-profiler-bucket-allocator-granularity=16"
    26. LOG    "memorysetup-profiler-bucket-allocator-bucket-count=8"
    27. LOG    "memorysetup-profiler-bucket-allocator-block-size=4194304"
    28. LOG    "memorysetup-profiler-bucket-allocator-block-count=1"
    29. LOG    "memorysetup-profiler-allocator-block-size=16777216"
    30. LOG    "memorysetup-profiler-editor-allocator-block-size=1048576"
    31. LOG    "memorysetup-temp-allocator-size-main=4194304"
    32. LOG    "memorysetup-job-temp-allocator-block-size=2097152"
    33. LOG    "memorysetup-job-temp-allocator-block-size-background=1048576"
    34. LOG    "memorysetup-job-temp-allocator-reduction-small-platforms=262144"
    35.  
    36. LOGLoading player data from data.unity3d
    37. LOGInitialize engine version: 6000.0.0f1 (4ff56b3ea44c)
    38. LOG[Subsystems] Discovering subsystems at path UnitySubsystems
    39. LOGCreating WebGL 2.0 context.
    40. LOGRenderer: WebKit WebGL
    41. LOGVendor:   WebKit
    42. LOGVersion:  OpenGL ES 3.0 (WebGL 2.0)
    43. LOGGLES:     3
    44. LOG EXT_clip_control EXT_color_buffer_float EXT_color_buffer_half_float EXT_depth_clamp EXT_polygon_offset_clamp EXT_texture_filter_anisotropic EXT_texture_norm16 KHR_parallel_shader_compile OES_draw_buffers_indexed WEBGL_clip_cull_distance WEBGL_compressed_texture_astc WEBGL_compressed_texture_etc WEBGL_compressed_texture_etc1 WEBGL_compressed_texture_pvrtc WEBKIT_WEBGL_compressed_texture_pvrtc WEBGL_debug_renderer_info WEBGL_debug_shaders WEBGL_lose_context WEBGL_multi_draw WEBGL_polygon_mode WEBGL_provoking_vertex GL_EXT_clip_control GL_EXT_color_buffer_float GL_EXT_color_buffer_half_float GL_EXT_depth_clamp GL_EXT_polygon_offset_clamp GL_EXT_texture_filter_anisotropic GL_EXT_texture_norm16 GL_KHR_parallel_shader_compile GL_OES_draw_buffers_indexed GL_WEBGL_clip_cull_distance GL_WEBGL_compressed_texture_astc GL_WEBGL_compressed_texture_etc GL_WEBGL_compressed_texture_etc1 GL_WEBGL_compressed_texture_pvrtc GL_WEBKIT_WEBGL_compressed_texture_pvrtc GL_WEBGL_debug_renderer_info GL_WEBGL_debug_shaders GL_WEBGL_lo
    45. LOGse_context GL_WEBGL_multi_draw GL_WEBGL_polygon_mode GL_WEBGL_provoking_vertex
    46. LOGOPENGL LOG: Creating OpenGL ES 3.0 graphics device ; Context level  <OpenGL ES 3.0> ; Context handle 1
    47. LOG[PhysX] Initialized SinglethreadedTaskDispatcher.
    48. LOGERROR: Shader
    49. LOGHidden/CoreSRP/CoreCopy shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
    50. LOGERROR: Shader
    51. LOGHidden/VoxelizeShader shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
    52. LOGERROR: Shader
    53. LOGHidden/Universal Render Pipeline/Edge Adaptive Spatial Upsampling shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
    54. LOGERROR: Shader
    55. LOGHidden/Universal/HDRDebugView shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
    56. LOGInput Manager initialize...
    57. LOGInput System initialize...
    58. LOGNew input system (experimental) initialized
    59.  
    60.  
     
    Last edited: May 13, 2024
  15. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    1,055
    I tried URP with WebGL in FPS Shooter, never saw such errors. No custom shaders for Non-AR version are here. I used this guide and this guide when migrating from BRP to URP. Try to replace indicated shaders in your log or upgrade them with this Unity converter.
     
  16. ashfaqueck

    ashfaqueck

    Joined:
    Jan 25, 2017
    Posts:
    9

    But the shader errors are fine I think. The issue is
    1. ERROR still waiting on run dependencies:
    2. ERROR dependency: wasm-instantiate
    3. ERROR (end of list)
    4. ERROR still waiting on run dependencies:
    5. ERROR dependency: dataUrl
    6. ERROR (end of list)