Search Unity

Hooking into WebGL/WASM loading process

Discussion in 'WebGL' started by sirrus, Sep 27, 2017.

  1. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    Is there a way to explicitly trigger the engine initialization when loading WebGL/WebAssembly?

    IOW, let WASM compile smoothly but then wait until some event before starting the next step/initialization?

    I know Chrome is working towards wasm streaming compilation (i.e, compile as it is downloaded) so it would be nice to let the system do that behind-the-scenes and be prepared for the engine initialization at a specific time.

    Thanks for any info.
     
  2. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,653
    There is a mechanism for doing that. You need to set
    Module["noInitialRun"] = true;
    on the game instance. Then, to run, simply call
    Module['callMain']();

    try the following:
    Code (csharp):
    1.  
    2. <!DOCTYPE html>
    3. <html lang="en-us">
    4.   <head>
    5. ...
    6.     <script>
    7.       var gameInstance = UnityLoader.instantiate("gameContainer", "Build/test.json", {onProgress: UnityProgress, Module: {
    8.         "noInitialRun": true,
    9.         onRuntimeInitialized: function () {
    10.             document.getElementById("callMainButton").innerHTML = "Run!";
    11.         },
    12.       }});
    13.       function callMain(){
    14.         gameInstance.Module['callMain']();
    15.       }
    16.     </script>
    17.   </head>
    18.   <body>
    19. ...
    20.    <button id="callMainButton" onclick="callMain()">Loading... please wait.</button>
    21.   </body>
    22. </html>
    23.  
     
    TheRoccoB and sirrus like this.
  3. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250