Search Unity

WebGL dataPath / absoluteURL

Discussion in 'Web' started by GamebookStudio, Jan 8, 2016.

  1. GamebookStudio

    GamebookStudio

    Joined:
    Sep 18, 2013
    Posts:
    10
    Hi,

    I've wrapped a simple WebGL build in my AngularJS website by just pasting the gist of the index.html in my existing layout.
    Code (JavaScript):
    1.           <div class="template-wrap clear">
    2.             <canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" height="550px" width="980px"></canvas>
    3.             <br>
    4.             <div class="logo"></div>
    5.             <div class="fullscreen"><img src="unity/TemplateData/fullscreen.png" width="38" height="38" alt="Fullscreen" title="Fullscreen" onclick="SetFullscreen(1);" /></div>
    6.           </div>
    7.           <script type='text/javascript'>
    8.             var Module = {
    9.               TOTAL_MEMORY: 268435456,
    10.               errorhandler: null,            // arguments: err, url, line. This function must return 'true' if the error is handled, otherwise 'false'
    11.               compatibilitycheck: null,
    12.               dataUrl: "unity/Release/Build-2.data",
    13.               codeUrl: "unity/Release/Build-2.js",
    14.               memUrl: "unity/Release/Build-2.mem",
    15.             };
    16.           </script>
    17.           <script src="unity/Release/UnityLoader.js"></script>
    The URL of the page that is showing the WebGL content is http://localhost:8000/some/other/path/page.html
    As you can see the WebGL content is hosted from the relative path app/unity/Release, and everything is actually running fine.

    Unfortunately the Application.absolutePath as well as Application.dataPath are not returning the path of where the WebGL content is hosted from but the URL of the page running it, in this case http://localhost:8000/some/other/path/ instead of http://localhost:8000/unity/Release/
    I need the proper URL though, because I need to load config files and other data stored next to the WebGL files, but i can't infer the URL correctly.

    Is this intended behaviour or should I send a bug report?

    BTW - the application was running the traditional Unity webplayer before the same way without issues.

    Cheers,
    Thomas
     
  2. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Application.absoluteURL and Application.dataPath are based on document.URL so http://localhost:8000/some/other/path/ seems consistent.

    you say that it should return http://localhost:8000/unity/Release/ but normally we return the location of the index.html, which is one level up, with no 'Release' in the path. So maybe it should be http://localhost:8000/unity...

    to me it's not a bug or maybe there is something i am not understanding.

    It would also be interesting to know how other people feel about Application.absoluteURL and Application.dataPath. Do you think they should return something else in your use-cases ?
     
  3. GamebookStudio

    GamebookStudio

    Joined:
    Sep 18, 2013
    Posts:
    10
    Hi Marco, thanks for your reply.

    We are embedding the WebGL content in quite a large AngularJS application and the page URL is not representing an actual file path but is a virtual representation of the navigation through the website. So in this example 'some' and 'other' and 'path' are not representing actual folders.

    I'm just migrating our Unity content from webplayer to WebGL and from my experience with the traditional webplayer, Application.dataPath is not necessarily connected to the URL of the website but always pointing to the location where the unity content is hosted.
    I need this information to access and load config files that are deployed along side the WebGL data, and at the current state there is no implicit way to retrieve this path.

    I think to be consistent with the known behaviour of the webplayer, Application.dataPath should probably point to the content location (int this case) http://localhost:8000/unity...

    Or if that's not possible, is there an alternative way to access the hosting location of the WebGL content?

    Thanks,
    Thomas
     
  4. diekeure

    diekeure

    Joined:
    Jan 25, 2013
    Posts:
    221
  5. philippehaw

    philippehaw

    Joined:
    Sep 8, 2016
    Posts:
    1
    Hi, I had the same problem. For me, It was solved typing GZ at the end of file's name :
    1. dataUrl: "unity/Release/Build-2.data",
    2. codeUrl: "unity/Release/Build-2.js",
    3. memUrl: "unity/Release/Build-2.mem",

      .dataGZ
      .jsGZ
      .memGZ
      1. dataUrl: "unity/Release/Build-2.datagz",
      2. codeUrl: "unity/Release/Build-2.jsgz",
      3. memUrl: "unity/Release/Build-2.memgz",

        This works for me.

        Thank you,
     
  6. ylhyh

    ylhyh

    Joined:
    Jun 14, 2016
    Posts:
    2
    Hi Marco-Trivellato, in my understanding, I expected the Application.dataPath return the folder path which place the "data" file, the developer may place custom data in the same folder with "data" file.
     
  7. farhankhwaja

    farhankhwaja

    Joined:
    Feb 28, 2017
    Posts:
    4
    Hi @Marco-Trivellato

    Well my issue is not related to this error, but since i couldn't find any post/question related to AngularJS + WebGL (unity Build) integration, i had to post this here.

    I made a webGL and ran on my localhost, it worked perfectly. But as soon as I add the built WebGL components to AngularJS, i am getting this error:

    Code (JavaScript):
    1. Invoking error handler due to
    2. Uncaught SyntaxError: Unexpected token <
    3.  
    4. blob:http://localhost:9000/7595cb44-1ea8-4fa5-9c48-a63ad62bf77f:1
    5. Uncaught SyntaxError: Unexpected token <
    I have searched everywhere on the internet but couldn't find any answer. I was hoping if you could help me out with this.
     
  8. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Personally I am not familiar with AngularJS. Perhaps someone else in this forum found a solution.
     
  9. FunkyFancy

    FunkyFancy

    Joined:
    Nov 23, 2016
    Posts:
    9
    Hey :) I'm searching also for a solution to integrate a unity WebGl build in Angular2 and stumbled over this post.
    I used your code and after a bit of trying i got it working. I changed the paths to this:

    Code (HTML):
    1. <script src="<%= APP_BASE %>assets/Release/UnityLoader.js "></script>
    This works in the index.html but how is it possible to get the canvas working in components?
    Do you have any idea for this? I would very glad if someone can tell me solution for this :D :)
     
  10. Creer_LLC

    Creer_LLC

    Joined:
    Feb 28, 2017
    Posts:
    15
    My question isn't related to this forum but i thought webgl could be loaded from cache after its been downloaded the first time but this seem not the case with my build. it keeps saying the memgz isnt functioning and second load takes time too. Please was i misinformed or there's something am doing wrong