Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Changes to the WebGL loader and templates introduced in Unity 2020.1

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

  1. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    541
    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,816
    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:
    112
    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:
    4
    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:
    4
    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:
    470
    Is there a loop preprocessor directive, or any way it could be achieved? See
     
  12. Skjalg

    Skjalg

    Joined:
    May 25, 2009
    Posts:
    208
    newguy123 and De-Panther like this.