Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Get a dll to work in WebGL

Discussion in 'Web' started by saifshk17, Mar 1, 2023.

  1. saifshk17

    saifshk17

    Joined:
    Dec 4, 2016
    Posts:
    488
    I have a dll file that I am using inside Unity and it works when I reference it in Windows build. However when I try make a WebGL build, the build fails because of the dll. How do I make the dll support WebGL as well?
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,420
  3. saifshk17

    saifshk17

    Joined:
    Dec 4, 2016
    Posts:
    488
    But is there a way that I can edit my dll file to support webgl platform?
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,420
    When you say „my DLL“ and by that you mean that you created that DLL file, then possibly. As long as the above is true. If you got that DLL from some place and it isn‘t working and there is no explicit mention of „supports Unity WebGL“ then no, absolutely no, it will not work.
     
  5. saifshk17

    saifshk17

    Joined:
    Dec 4, 2016
    Posts:
    488
    yeah you are right. I have created this dll. It already is supported on Windows platform. Just have no clue on how to make this possible on WebGL as well.
     
  6. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,420
    Throw the code of that DLL into the project itself and remove the DLL. Then check if the build works. If it doesn't, you may get a better error message I hope.

    But if you use namespaces, classes or other DLLs (ie Windows API native calls like FileBrowser) in the DLL that aren't available in Unity scripting and that was the reason to make that DLL, then it's just not going to work. WebGL (browser in general) is a restricted platform, more so than any other including iOS and UWP.
     
  7. sinaari

    sinaari

    Joined:
    Jan 28, 2019
    Posts:
    47
    Well, you never said if the DLL was native or not.

    To whoever finds this thread, and wonders about using a native DLL in a WebGL build -- yes, that is possible if you have the source code of it. See the following links:
    Of course this is not a simple topic and there might be some restrictions, but I guess that whatever works with Emscripten is just going to work.

    If your DLL is managed then it might be possible too, if Unity manages to do its IL2CPP thing on it.

    However, native DLLs required by managed (.NET) DLLs might not actually work, I'm not sure if Unity is going to properly recognize the dependency and pack everything correctly. Most probably some trick like re-linking all the native DLL functions from your code, to maintain the signatures for the linker, or including the managed DLL instead in its source form, with explicit references for the functions from the native one, might work.
     
    Last edited: Mar 22, 2024