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

How to generate a .wasm file when building

Discussion in 'WebGL' started by Takezo_00, Dec 31, 2020.

  1. Takezo_00

    Takezo_00

    Joined:
    Aug 23, 2020
    Posts:
    3
    Thought this would be a simple question but I've searched everywhere, save for posting here.

    Anywho, trying to upload my game to Simmer.io, which requires a wasm file for uploading except no matter how I configure the build settings in Unity, I end up without a wasm file (I DO get a .asm file, however).

    I've tried this with Unity 2020 1.3f1 and the latest version of Unity, and I have no idea what’s happening. In player settings, I did notice that I’m building based on WebGL 2.0 graphics API. I’ve searched around and can’t seem to figure this one out.

    Heres the build output:

    Here are my player settings:

    upload_2020-12-31_12-58-50.png
    upload_2020-12-31_12-59-20.png
    upload_2020-12-31_12-59-38.png
    Hoping someone can help, thanks!
     
  2. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    584
    This is an example on how you can achieve it.

    - Create a folder "editor" in your assets folder
    - Create a C# script called WebAssemblyOption in the editor folder.
    Past this inside :

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEditor;
    6.  
    7. public class WebAssemblyOption
    8. {
    9.     [MenuItem("Web Assembly/Enable Threads Support")]
    10.     static void EnableThreads()
    11.     {
    12.         PlayerSettings.WebGL.threadsSupport = true;
    13.         ToggleActionValidate();
    14.     }
    15.  
    16.     [MenuItem("Web Assembly/Disable Threads Support")]
    17.     static void DisableThreads()
    18.     {
    19.         PlayerSettings.WebGL.threadsSupport = false;
    20.         ToggleActionValidate();
    21.     }
    22.  
    23.     [MenuItem("Web Assembly/Enable Wasm Only")]
    24.     static void EnableWasm()
    25.     {
    26.         PlayerSettings.WebGL.linkerTarget = WebGLLinkerTarget.Wasm;
    27.         WasmActionValidate();
    28.     }
    29.  
    30.     [MenuItem("Web Assembly/Disable Wasm Only")]
    31.     static void DisableWasm()
    32.     {
    33.         PlayerSettings.WebGL.linkerTarget = WebGLLinkerTarget.Both;
    34.         WasmActionValidate();
    35.     }
    36.  
    37.     [MenuItem("Web Assembly/Threads Support Active", false)]
    38.     public static bool ToggleActionValidate()
    39.     {
    40.         Menu.SetChecked("Web Assembly/Threads Support Active", PlayerSettings.WebGL.threadsSupport);
    41.         return true;
    42.     }
    43.  
    44.     [MenuItem("Web Assembly/Wasm Only", false)]
    45.     public static bool WasmActionValidate()
    46.     {
    47.         Menu.SetChecked("Web Assembly/Wasm Only", PlayerSettings.WebGL.linkerTarget == WebGLLinkerTarget.Wasm?true:false);
    48.         return true;
    49.     }
    50.  
    51. }
    52.  
    Compile and you will have a new menu in your unity called "Web Assembly" (where you have file,edit,assets ect ....)
    Click "Web Assembly/Disable Wasm Only" == > compile and you will have both .asm and .wasm
     
  3. GoblinGameWorks

    GoblinGameWorks

    Joined:
    Sep 14, 2019
    Posts:
    13
    I have tried this and I get the following error:

    Assets\Editor\WebAssemblyOption.cs(32,45): error CS0619: 'WebGLLinkerTarget.Both' is obsolete: 'WebGLLinkerTarget.Both mode is no longer supported. Instead you can create separate asm.js and WebAssembly builds and download the appropriate one depending on the browser capabilities.'
     
  4. OleksandrMartysh

    OleksandrMartysh

    Joined:
    Dec 13, 2015
    Posts:
    25
    You can force Unity to build both by editing this line in ProjectSettings.asset file in your Project/ProjectSettings folder:
    webGLLinkerTarget: 2
    0 = asm.js
    1 = Wasm
    2 = both

    P.S. I am not sure, that it is still possible for Unity 2021+, because asm.js is deprecated from this version of Unity.
     
    carloscorcha likes this.