Search code examples
c#unity-game-engineunresolved-external

Undefined Symbol: LoadExtern on Unity WebGL build


I have a class SaveSystem which contains 2 extern methods: SaveExtern, LoadExtern these methods are supposed to be loaded externally from a lib in order to maintain cloud progress saving. But after this, Unity started to throw these errors on build. What may be the cause and how can I fix it.

Error

Library\Bee\\artifacts\WebGL\build\debug_WebGL_wasm\build.js: undefined symbol:
LoadExtern (referenced by top-level compiled C/C++ code)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

Code

[DllImport("__Internal")]
private static extern void SaveExtern(string data);
    
[DllImport("__Internal")]
private static extern void LoadExtern();

I tried reinstalling Unity, deleting everything from \Library, including #if UNITY_WEBGL and #if !UNITY_EDITOR && UNITY_WEBGL


Solution

  • The answer was rather simple:

    • You need to create a file anyname.jslib in folder /Plugins in your /Assets and implement methods you need inside this file.

    You may find info about it here.

    https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html

    Big thanks to derHugo for making up my mind