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

Question Webgl Build Failed

Discussion in 'Editor & General Support' started by videossuper098, Oct 2, 2023.

  1. videossuper098

    videossuper098

    Joined:
    Sep 24, 2022
    Posts:
    3
    So I am creating a unity webgl game. I want my script to know at runtime if the webgl game in the browser is on Desktop or A mobile device so I used the following method:
    -I created a file named "MyPlugin.jslib" in Assets/Plugins/webgl/MyPlugin.jslib
    that isn what i wrote inside this file:

    var MyPlugin = {
    IsMobile: function()
    {
    return Module.SystemInfo.mobile;
    }
    };
    mergeInto(LibraryManager.library, MyPlugin);

    -Then I added following to my unity script:

    using System.Runtime.InteropServices;
    #region WebGL is on mobile check
    [DllImport("__Internal")]
    private static extern bool IsMobile();
    public bool isMobile()
    {
    #if !UNITY_EDITOR && UNITY_WEBGL
    return IsMobile();
    #endif
    return false;
    }
    #endregion

    I used bool isMobile() to Check if the device on which my webgl game is running is a mobile device or not. Everything worked fun in editor. But when I sarted to build the game. The build failed and these errors showed:

    'Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js: undefined symbol: IsMobile (referenced by top-level compiled C/C++ code)
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun ()'

    'Building Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js failed with output:
    error: undefined symbol: IsMobile (referenced by top-level compiled C/C++ code)
    warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
    warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
    warning: _IsMobile may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
    Error: Aborting compilation due to previous errors
    emcc2: error: '"C:/Software/unity 2021 new/2021.3.11f1/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/node/node.exe" "C:\Software\unity 2021 new\2021.3.11f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\src\compiler.js" C:\Users\Hp\AppData\Local\Temp\tmpjf_g3fkj.txt' failed (1)
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun ()
    '

    Please help resolve this and if there is some other way from which I can check device type then that will work too. Thanks
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    It looks like you're doing everything correctly.

    Is your plugin marked (in the inspector) to be included with WebGL?

    That should be automatic but since you lowercased the
    Plugins/webgl/
    directory, maybe it didn't get set?
     
  3. videossuper098

    videossuper098

    Joined:
    Sep 24, 2022
    Posts:
    3
    Yes the webgl is check. and my project is also on webgl platform
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563