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. Dismiss Notice

WebGL build not working correctly. "UnityLoader is not defined".

Discussion in 'Editor & General Support' started by doronhn, Sep 25, 2020.

  1. doronhn

    doronhn

    Joined:
    Jul 27, 2018
    Posts:
    27
    hey,
    i have two issues with my unity when i try to build for WebGL.
    Unity ver- 2020.1.6f1


    1. after build is finished when i open console - i see the error- "UnityLoader is not defined".
    this is important from my side cause i am need to use the "unityInstance" to send message to unity scripts.

    2. all the Template Tags not been replaces with the real value, and stay the same- %XXX%.

    --- i am using this custom template to get responsive template - https://github.com/sno/unity-webgl-responsive ---

    this is my HTML:



    Code (JavaScript):
    1.  
    2. <html lang="en-us">
    3.  
    4.   <head>
    5.     <meta charset="utf-8">
    6.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    7.     <title>%UNITY_WEB_NAME%</title>
    8.  
    9.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
    10.  
    11.     <link rel="stylesheet" href="assets/css/reset.css">
    12.     <link rel="stylesheet" href="assets/css/style.css">
    13.  
    14.     <script src="assets/js/jquery-3.4.1.min.js"></script>
    15.  
    16.     <!-- unity resources -->
    17.     <script src="%UNITY_WEBGL_LOADER_URL%"></script>
    18.  
    19.     <script>
    20.       // instantiate webgl only if we're not on a touch device
    21.  
    22.       var isTouch = ('ontouchstart' in document.documentElement);
    23.  
    24.       if ( !isTouch ) {
    25.         var unityInstance = UnityLoader.instantiate("unityContainer", "%UNITY_WEBGL_BUILD_URL%");
    26.       }
    27.     </script>
    28.   </head>
    29.  
    30.   <body>
    31.  
    32.     <div class="webgl-wrapper">
    33.         <div class="webgl-content">
    34.           <div id="unityContainer" style="width:%UNITY_WIDTH%px; height: %UNITY_HEIGHT%px;"></div>
    35.         </div>
    36.     </div>
    37.  
    38.     <div class="info">
    39.       <p>unity webgl responsive</p>
    40.       <p>press F or <a href="#" onclick="unityInstance.SetFullscreen(1)">click here</a> to toggle fullscreen</p>
    41.     </div>
    42.  
    43.     <!-- feel free to remove all credits! -->
    44.     <div class="info">
    45.       <p>source code on <a href="https://github.com/sno/unity-webgl-responsive">github</a></p>
    46.       <p>template by dom / <a href="https://twitter.com/zerstoerer">@zerstoerer</a></p>
    47.     </div>
    48.  
    49.     <script src="assets/js/app.js"></script>
    50.   </body>
    51.  
    52. </html>
    53.  
    54.  
    55. need your help
    56. thanks
    57.  
     
  2. BitingCold

    BitingCold

    Joined:
    Apr 9, 2019
    Posts:
    4
    Hi! I've spotted that WebGL plugins API for Unity 2019.x and 2020.x are not (completely) backwards compatible. UnityLoader seems to be deprecated from Unity 2020.x, I had the same issue when one of my plugins tried to access it.
    Hope it helps!
     
    ENOUGH- likes this.
  3. khamzah22

    khamzah22

    Joined:
    Sep 10, 2021
    Posts:
    2
    how were you able to resolve this?
     
    keil_unity likes this.
  4. DeanX

    DeanX

    Joined:
    Mar 1, 2016
    Posts:
    4
    What is the replacement for UnityLoader?
     
    McDuckEnterprises and ENOUGH- like this.
  5. exafred

    exafred

    Joined:
    Aug 23, 2013
    Posts:
    2
    Not sure how relevant this still is, but I've just come across this issue too. BitingCold is right; Unity 2020's WebGL builds are not compatible with Unity 2019's!

    In case it helps anyone in the future:

    Template Tags are no longer
    %thing%
    - they're now
    {{{ thing }}}
    , and the broad layout of the HTML / JS / CSS has also changed. Info about this new stuff seems to start at "Structure of the index.html file" on https://docs.unity3d.com/2020.2/Documentation/Manual/webgl-templates.html.

    Unity 2020 Templates, for me on Windows, were in
    (installationPathOfMy2020Editor)\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\WebGLTemplates


    For UnityLoader
    As far as I can tell, UnityLoader is sorta-combined with the rest of the build JavaScript, but (maybe?) only when you set Decompression Fallback to true in the Publishing Settings. There should be no need to include
    UnityLoader.js
    explicitly, though I can't confirm this myself.

    Images!
    Image filenames in the
    TemplateData
    folder have also changed; I couldn't figure out why my progress bar wasn't showing... But this was why.

    Attached is my Unity installation's "Default" WebGL Template
     

    Attached Files:

    paladim and BSK13118 like this.
  6. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    869
    Isnt it amazing how "they" just decide to change important stuff like that on the fly? This happens so often in the computer field, somebody decide to change something that everyone is using, then build all over the world starts breaking, projects take a nose dive, companies go out of business, loose funding, lives get broken, all because someone decide to change %thing% to {{{thing}}} deep in the code somewhere. I think Unity is hiring mostly random software people who come in and ransack code and leave not caring who it hurts.
     
    paladim, abbasjafari and BSK13118 like this.
  7. anguha

    anguha

    Joined:
    May 4, 2023
    Posts:
    23
    I updated the webgl-template using the latest index.html. However I am still getting the error Unityloader.js not found. And I checked that after the build is complete, the webgl/build directory does not contain the Unityloader script. It is required though because the `createUnityInstance` function used in index.html script tag is defined in the unityloader script only.

    Does anyone know the solution to this problem?
     
  8. BreckCooper

    BreckCooper

    Joined:
    Oct 16, 2019
    Posts:
    2
    Did anyone ever figure out the syntax for this? Going from the 2019 to the 2020 documentation, it's not very clear how to handle
    Code (CSharp):
    1. UnityLoader.instantiate("unityContainer", "%UNITY_WEBGL_BUILD_URL%");