Search Unity

Changes to the WebGL loader and templates introduced in Unity 2020.1

Discussion in 'Web' started by alexsuvorov, Jan 28, 2020.

  1. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    I never heared of "Web Assets" folder.
    There's "WebGLTemplates" for HTML templates which also in the past (when Unity supported its own flavor of JavaScript/UnityScript) was the only folder that could contain ".js" files that the compiler ignored.
    And there's the "StreamingAssets" folder, which is where you should put content for the game to download after the initial download/loading.
     
  2. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    As I said me either so I think @John-B should post a screen of what folder they are referring to.

    Thanks,
    jrDev
     
  3. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    118
    Hello everyone,

    We have a problem with our web page and the WebGL Unity compilation since we did the upgrade from Unity 2018.3.2f1 to Unity 2020.3.18f1

    We realized the changes in the WebGL build and we have tried to do the necessary changes in our site to make things work, but with no luck.

    The problem we have is that we use a website with panels and the UpdatePanel component because we don't want a full web page to reload.

    We have seen that the plugin is loaded, but it is not initialized.

    Does anyone have this problem with panels? It is necessary for the CreateUnityInstance to be done at PageLoad?

    Thanks in advance!
     
  4. Georgeygeorge

    Georgeygeorge

    Joined:
    Feb 6, 2022
    Posts:
    2
    Hi all,

    A repeat topic, maybe been some advances since last discussed, any input much appreciated:

    Trying to get a brotli compressed webgl to work on my site.

    1. Uncompressed webgl build loads fine to my site through shared host server (litespeed)

    2. But compressed brotli build results gives:

    a) In Chrome console -
    Uncaught SyntaxError: Invalid or unexpected token

    b) On website -
    Unable to parse Build/’xxx’.framework.js.br! This can happen if build compression was enabled but web server hosting the content was misconfigured to not serve the file with HTTP Response Header "Content-Encoding: br" present. Check browser Console and Devtools Network tab to debug

    Note:

    Host server settings enabled for brotli & mime
    Johannski's suggested script for litespeed inserted with .htaccess on server, (thanks!).
    Unity v2021.2.11f1

    Is there something I should target for a) ?


    Many thanks
     
    newguy123 likes this.
  5. faziii

    faziii

    Joined:
    Jun 11, 2019
    Posts:
    17
    In Unity 2021.1.0 I am trying to do the same want to write a general loader. I followed above instruction but my build is not loading correctly. I have replaced all read function data with UnityLoader/xxx like this: I have changed following lines:
    Code (CSharp):
    1. { { { read("UnityLoader/FetchWithProgress.js") }}}
    2. { { { read("UnityLoader/UnityCache.js") }}}
    3. { { { read("UnityLoader/CachedFetch.js") }}}
    4. require: {{{ read("UnityLoader/Gzip.js") }}},
    5.   require: { { { read("UnityLoader/Brotli.js") }}},
    It showing Uncaught ReferenceError: read is not defined.

    I watch loader js have these things are not preprocess completely.
    { { { read("UnityLoader/FetchWithProgress.js") }}}
    { { { read("UnityLoader/UnityCache.js") }}}
    { { { read("UnityLoader/CachedFetch.js") }}}
     
    Last edited: May 20, 2022
  6. ricardo_charf_coatsink

    ricardo_charf_coatsink

    Joined:
    Feb 10, 2021
    Posts:
    1
    Hey all!

    I added some java script macros on my template and they correctly appear in the player settings window.
    But I have a question here::

    Is there a way to set those custom macro values by code?

    I ask this because for now, the only way I see to change them is through the player settings UI. Which is good to have but is not enough for what I need.

    I'd be really glad to know, since I found nothing regarding this elsewhere.

    Thanks in advance

    EDIT:
    I managed to discover how to do it in the end, even before this post was posted...
    So here it is:

    PlayerSettings.SetTemplateCustomValue(<macroName>, <stringValue>);


    I was looking for it on the build options, but it was in the PlayerSettings class after all
     
    Last edited: Jul 11, 2022
    newguy123 likes this.
  7. dbgns

    dbgns

    Joined:
    Sep 1, 2022
    Posts:
    1
    Hi!

    I am using mediapipe javascript api to process the video captured by `WebCamTexture` in unity webgl.

    In unity2019 it seems that builder will generate a <video></video> tag in index.html. But in unity 2021 I can't find this tag(it's replace with unity-container and canvas), so I can't fetch the video and feed to mediapipe js scripts.

    Do you have any idea on this problem?

    Thanks!
     
  8. BugzHunter

    BugzHunter

    Joined:
    May 7, 2019
    Posts:
    5
    Are you sure it works for .*,json files? I have Unity 2020.3.38f1, json is located in path:
    Assets/WebGLTemplates/Local/Build/WebGL.json
    and it don't get preprocessed on build. Here is content:
    Code (JavaScript):
    1. {
    2.     "dataUrl": "{{{ DATA_FILENAME }}}",
    3.     "frameworkUrl": "{{{ FRAMEWORK_FILENAME }}}",
    4.     "codeUrl": "{{{ CODE_FILENAME }}}",
    5. #if MEMORY_FILENAME
    6.     "memoryUrl": "{{{ MEMORY_FILENAME }}}",
    7. #endif
    8. #if SYMBOLS_FILENAME
    9.     "symbolsUrl": "{{{ SYMBOLS_FILENAME }}}",
    10. #endif
    11.     "streamingAssetsUrl": "StreamingAssets",
    12.     "companyName": "{{{ JSON.stringify(COMPANY_NAME) }}}",
    13.     "productName": "{{{ JSON.stringify(PRODUCT_NAME) }}}",
    14.     "productVersion": "{{{ JSON.stringify(PRODUCT_VERSION) }}}"
    15. }
    Is there something wrong with it?
     
  9. BugzHunter

    BugzHunter

    Joined:
    May 7, 2019
    Posts:
    5
    I've found the culprit! Preprocessed file can't be in
    Assets/WebGLTemplates/*/Build
    directory. :)
     
  10. xAdamQ

    xAdamQ

    Joined:
    Jul 23, 2016
    Posts:
    53
    this is a config for brtotli, for gzip use the appropriate file extensions. some of these binding are unnecessary.

    Code (Boo):
    1.  
    2. server{ listen 443 ssl default_server;
    3.  
    4.         location ~ \.br$ {
    5.                 add_header Content-Encoding br;
    6.  
    7.                 location ~ \.data\.br$ {
    8.                         types { }
    9.                         default_type application/octet-stream;
    10.                 }
    11.                 location ~ \.wasm\.br$ {
    12.                         types { }
    13.                         default_type application/wasm;
    14.                 }
    15.                         location ~ \.js\.br$ {
    16.                         types { }
    17.                 default_type application/javascript;
    18.                 }
    19.         }
    20.  
    21.         location ~ \.js$ {
    22.                 types { }
    23.                 default_type application/javascript;
    24.         }
    25.  
    26.         location / { try_files $uri $uri/ $uri.html =404;
    27.         }
    28.  
    29.         error_page 404 /404.html;
    30.  
    31.         brotli_static on;
    32. }
    33.  
     
  11. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    547
    Is there a loop preprocessor directive, or any way it could be achieved? See
     
  12. Skjalg

    Skjalg

    Joined:
    May 25, 2009
    Posts:
    211
    newguy123 and De-Panther like this.
  13. Hashirali890

    Hashirali890

    Joined:
    Mar 18, 2018
    Posts:
    2
    can anyone share unityloader.js script with me because i am not able to find it
    in my template folder
     
  14. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    UnityLoader.js file is not part of the WebGL Template, but part of Unity. You can find it for example on Windows at

    C:\Program Files\Unity\Hub\Editor\2022.3.9f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\UnityLoader\UnityLoader.js
     
  15. lazer

    lazer

    Joined:
    Aug 15, 2012
    Posts:
    23
    Hi @jukka_j -

    I'm trying to optimize the loading experience of our app. Our app data is very lightweight and the wasm is much larger than the data. In this scenario the default loader's progress UX fails pretty badly. After poking at the UnityLoader code (on 2022.3.10f1), I'm not sure if this was by design or just an architectural oversight, because it seems to defer loading of the .wasm to the framework js, but there is no mechanism to report download progress back in to loader which smartly tracks progress for multiple parallel downloads.

    Our target audience includes seniors, folks with cognitive impairment, slow connections, etc so having the progbar stall at 90% for a relatively large and unknown amount of time _on the happy path_ is unacceptable. If I enable Decompression Fallback that forces the wasm to load through the loader and not the framework and I get desired behavior and the progress bar tracks both code and data downloads. However I see from other threads that you guys rightly want to deprecate that feature.

    Is this a scenario where I should create a custom loader? Or are you guys planning to fix the framework loader so that all download progress is reported properly at some point?

    Thanks!
     
    KamilCSPS likes this.