Search Unity

Web assembly streaming wasmCodeUrl doesn't respect relative host of a CDN

Discussion in 'Web' started by whiskers434, Apr 25, 2020.

  1. whiskers434

    whiskers434

    Joined:
    Sep 23, 2014
    Posts:
    28
    Hi,

    So I have my web gl app hosted on a .net mvc azure app service with the web gl build hosted in a azure storage account accessed via a CDN end point, this was all working fine until I tried enabling Web assembly streaming and instead of getting the .wasm file from the CDN where the json file is, it's trying to get it from the app domain i.e its not respecting the relative host of the CDN tho it does for the dataUrl when Web assembly streaming is not enabled.

    If I host the build files in the app it works fine as the domain is then correct. Even setting a absolute url in the json file doesn't work as it appends the app domain to the absolute url of the cdn end pointed file.

    My current line of thinking is I need to make a change in the UnityLoader.js to change how it handles the wasmCodeUrl from the josn file but its minified and hard to read and edit.

    Anyone any other ideas for what I have missed?

    Code (CSharp):
    1. @{
    2.     <link rel="stylesheet" href="https://mydomain.azureedge.net/myapp/TemplateData/style.css">
    3.     <script src="https://mydomain.azureedge.net/myapp/TemplateData/UnityProgress.js"></script>
    4.     <script src="https://mydomain.azureedge.net/myapp/Build/UnityLoader.js"></script>
    5. }
    6. <script>
    7.     var gameInstance = UnityLoader.instantiate("gameContainer", "https://mydomain.azureedge.net/myapp/Build/WebGL.json", { onProgress: UnityProgress });
    8. </script>
    9.  
    10. <div>
    11.     <div id="gameContainer" style="width: 960px; height: 600px"></div>
    12. </div>
    Code (CSharp):
    1. {
    2. "companyName": "myCompany",
    3. "productName": "myapp",
    4. "productVersion": "0.1",
    5. "dataUrl": "WebGL.data.unityweb",
    6. "wasmCodeUrl": "WebGL.wasm",
    7. "wasmFrameworkUrl": "WebGL.wasm.framework.unityweb",
    8. "graphicsAPI": ["WebGL 2.0"],
    9. "webglContextAttributes": {"preserveDrawingBuffer": false},
    10. "splashScreenStyle": "Dark",
    11. "backgroundColor": "#231F20",
    12. "cacheControl": {"default": "must-revalidate"},
    13. "developmentBuild": false,
    14. "multithreading": false,
    15. "unityVersion": "2019.3.10f1"
    16. }
     
  2. Apollo-Meijer

    Apollo-Meijer

    Joined:
    Mar 30, 2015
    Posts:
    31
    Did you eventually solve this issue?
     
  3. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    If you look at the generated .html file, you can see the URLs that are used to load different resources:

    Code (JavaScript):
    1.       var buildUrl = "Build";
    2.       var loaderUrl = buildUrl + "/build_webgl.loader.js";
    3.       var config = {
    4.         dataUrl: buildUrl + "/build_webgl.data",
    5.         frameworkUrl: buildUrl + "/build_webgl.framework.js",
    6.         codeUrl: buildUrl + "/build_webgl.wasm",
    7.         streamingAssetsUrl: "StreamingAssets",
    8.         companyName: "DefaultCompany",
    9.         productName: "Test URP 2021",
    10.         productVersion: "0.1",
    11.         showBanner: unityShowBanner,
    12.       };
    13.  
    There you can customize the URLs that one should use to download the files from. Use a custom WebGL template ( https://docs.unity3d.com/2021.1/Documentation/Manual/webgl-templates.html ) to carry changes to the index file through rebuilds.
     
  4. Apollo-Meijer

    Apollo-Meijer

    Joined:
    Mar 30, 2015
    Posts:
    31
    Thanks @jukka_j Will do this when we move to new unity version