Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question running WebGL build in mobile-app via WebView with AssetBundles?

Discussion in 'Web' started by Matt_at_mindtrigger, May 29, 2021.

  1. Matt_at_mindtrigger

    Matt_at_mindtrigger

    Joined:
    Jan 20, 2014
    Posts:
    60
    Hi,

    a very specific question from a client came up the other day. We are tasked with building a WebGL-solution primarily for their website. Among other things they also plan to include this website in a pre-existing mobile-app of theirs via WebView.

    First Question:
    Does anyone have any experience on whether this would work / what kinds of problems could arise?

    Second Question:
    The WebGL-solution will use several AssetBundles with lots of 3d-Geometry to be loaded dynamically during runtime. The client asked whether in case you'd be using the WebView in their pre-existing mobile-app: Could those AssetBundles be downloaded/installed with the app itself (and put into the Cache) so in that case you would not have to stream them on-the-fly? (They are worried about slow internet-connections)

    I'm currently still using Unity 2018.2.21f1 but switching to higher versions is an option.
    Any knowledge on those topics is appreciated, thanks in advance!
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,401
    i think the main problem is that unity webgl doesnt officially support mobile devices:
    https://docs.unity3d.com/Manual/webgl-browsercompatibility.html
     
  3. Matt_at_mindtrigger

    Matt_at_mindtrigger

    Joined:
    Jan 20, 2014
    Posts:
    60
    Thank you,
    I'm aware of that.

    I should've been more specific, sorry:

    We use our Unity WebGL-solutions on mobile just fine. So from prior projects we already know that we will be able to run the project there (we make 3 GB of RAM a prerequisite by disclaimer).

    However we cannot answer the questions stated above regarding WebView and local AssetBundles.
    Anyone happens to have some experience on those issues?
     
  4. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Running WebGL builds in a WebView should work - although details on which version of the web view may cause variations. When running in a WebView you are probably defining your custom embedding/sandboxing/CSP rules, so make sure those allow Wasm compilation. (see https://www.aaron-powell.com/posts/2019-11-27-using-webassembly-with-csp-headers/ for most recent details on this)

    Also since the code will be running from an embedded host, if it does XHRs to external servers outside the WebView, be sure to adjust any CORS rules accordingly on the external servers.

    It should be possible to bundle assets to be served locally. I haven't done that before, but I think this API https://developer.android.com/reference/androidx/webkit/WebViewAssetLoader should be the way to go. Asset downloads may need to use absolute URLs instead of relative for them to work.

    If the assets are sourced locally, recommend disabling the Unity project build setting "Data Caching" altogether.

    Definitely recommend updating to Unity latest 2020.3 LTS. At Unity 2020.1 the WebGL template and loader system was reworked to improve startup time parallelism and make the file structure leaner. The inflexible .unityweb scheme was also removed.
     
    KamilCSPS likes this.
  5. Matt_at_mindtrigger

    Matt_at_mindtrigger

    Joined:
    Jan 20, 2014
    Posts:
    60
    Nice,
    that's good to know.

    Thank you!