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. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Question Tiny Builds for Web Building and Distribution

Discussion in 'Project Tiny' started by silverduck, Oct 26, 2020.

  1. silverduck

    silverduck

    Joined:
    May 16, 2010
    Posts:
    27
    Hello. My background is largely in Unity and I'm largely ignorant of things like web servers and how the internet works.

    I've made my first Tiny Project and it builds and it runs on the localhost just fine (in both asmjs and wasm) but I have no idea how to get from there to actually uploading it to a domain so that I can just send someone a link they can click and play my Tiny build.

    I understand that this is probably outside of the scope of this forum and is likely a fairly long process, but really any guidance would be appreciated.
     
  2. AbdulAlgharbi

    AbdulAlgharbi

    Unity Technologies

    Joined:
    Jul 27, 2018
    Posts:
    319
    • I would suggest that you build a release configuration of the game.
    • Have a simple html page with a script to pick wasm/asmjs and you can host that anywhere
    • your site should look something like(Just example) :
    |
    index.html
    |
    Preview_Image.png
    |
    -- Wasm
    |
    -- Asmjs

    in the index.html put something like the following:
    Code (CSharp):
    1. <!DOCTYPE HTML>
    2. <html>
    3. <head>
    4. <meta property="og:title" content="My Game" />
    5. <meta property="og:description" content="Details about the game" />
    6. <meta property="og:image" content="./Preview_Image.png" />
    7. </head>
    8. <body>
    9.     <script type="text/javascript">
    10.         var wasmurl = "./Wasm/MyGame.html";
    11.         var asmurl = "./Asmjs/MyGame.html";
    12.         try {
    13.             if (typeof WebAssembly === "object") {
    14.                 document.location.replace(wasmurl);
    15.             } else {
    16.                 document.location.replace(asmurl);
    17.             }
    18.         } catch (e) {
    19.             document.location.replace(asmurl);
    20.         }
    21.     </script>
    22.  
    23.     <img src="./Preview_Image.png" width="0" height="0">
    24. </body>
    25. </html>
    Preview_Image.png is the site preview that shows up when you share the link
    • Maybe also have a fav icon but its really up to you how to host and where
    • I know you can use GitHub pages https://pages.github.com/ but I never tried it
     
    silverduck likes this.
  3. silverduck

    silverduck

    Joined:
    May 16, 2010
    Posts:
    27
    Thank you very much for the quick response. I think this index.html will come in very handy when I'm ready to upload somewhere.

    But when I just click on that index.html file I get the following errors in chrome...

    [Error] Cross origin requests are only supported for HTTP.
    (anonymous function) (Runtime.html:1:2082)
    Promise
    binary (Runtime.html:1:1965)
    Global Code (Runtime.html:1:2359)
    [Error] XMLHttpRequest cannot load file:///Users/viewermac/Documents/Websites/UnityTiny01/wasm/Runtime.js due to access control checks.
    (anonymous function) (Runtime.html:1:2082)
    Promise
    binary (Runtime.html:1:1965)
    Global Code (Runtime.html:1:2359)
    [Error] Cross origin requests are only supported for HTTP.
    (anonymous function) (Runtime.html:1:2082)
    Promise
    binary (Runtime.html:1:1965)
    Global Code (Runtime.html:1:2380)
    [Error] XMLHttpRequest cannot load file:///Users/viewermac/Documents/Websites/UnityTiny01/wasm/Runtime.wasm due to access control checks.
    (anonymous function) (Runtime.html:1:2082)
    Promise
    binary (Runtime.html:1:1965)
    Global Code (Runtime.html:1:2380)
    [Error] Not allowed to load local resource: file:///favicon.ico


    I'm starting to think that this is normal and that I shouldn't expect to be able to run my tiny builds just by clicking the HTML file. And by extension, I shouldn't expect to be able to send the game to a friend and tell them to click the index.html file to play the game. Is this correct?

    Or if it should be possible to just click on index.html and start the game running, is there some simple step that I'm missing? What is it that the "Run" button in Unity is doing that sets up the game on a localhost port and plays it?
     
  4. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    875
    @silverduck you need to use a web server to host/run the web build. When you press build and run inside Unity, we start a local web server for you in the background. If you want your friends to play your creation, I would suggest hosting the build on a hosting site and give them the url to the creation.

    If you want to run the build locally without Unity, see the section "Running a simple local HTTP server" here.
     
    silverduck likes this.
  5. silverduck

    silverduck

    Joined:
    May 16, 2010
    Posts:
    27
    Thank you very much. This thread has been incredibly helpful.
     
    Ted_Wikman likes this.