No WebGL possible with PUN 2

Options
Hello everyone,

I am new to Photon/PUN and also quite new to unity. I have a problem using PUN 2 and could not find a solution up to now:

I just wanted to test if PUN 2 works also in WebGL Builds, as far as I know it should. But I am not able to get a working WebGL Build with PUN 2. I tried it also with the Demos (especially the SlotCar Demo) you can get with PUN (to be sure, that nothing in my Project creates the problem), but even then I can't get a working WebGL Build. When I build the Demo as Windows Standalone, everything works fine and I also can get a connection to the server from different clients.
When I want to build WebGL, I first got a build, but it never left the Unity/WebGL loading screen. And now after I updated Unity and PUN 2 to the current version I am not even able to get a build.

I give you a short history of what I tried:

When I open an empty unity (3D) project, I already get a warning:
Assembly for Assembly Definition File 'Packages/com.unity.collab-proxy/Tests/Editor/Unity.CollabProxy.EditorTests.asmdef' will not be compiled, because it has no scripts associated with it.
UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget, String[])

after importing PUN 2, there are several warnings:
Unity is only able to load mdb or portable-pdb symbols. Assets/Photon/PhotonLibs/Metro/Photon3Unity3D.pdb is using a legacy pdb format.
UnityEngine.Debug:LogWarning(Object)
Microsoft.Unity.VisualStudio.Editor.VisualStudioEditor:SyncIfNeeded(String[], String[], String[], String[], String[]) (at Library/PackageCache/com.unity.ide.visualstudio@2.0.2/Editor/VisualStudioEditor.cs:154)
UnityEditor.AssetPostprocessingInternal:PostprocessAllAssets(String[], String[], String[], String[], String[])

Unity is only able to load mdb or portable-pdb symbols. Assets/Photon/PhotonLibs/netstandard2.0/Photon3Unity3D.pdb is using a legacy pdb format.
UnityEngine.Debug:LogWarning(Object)
Microsoft.Unity.VisualStudio.Editor.VisualStudioEditor:SyncIfNeeded(String[], String[], String[], String[], String[]) (at Library/PackageCache/com.unity.ide.visualstudio@2.0.2/Editor/VisualStudioEditor.cs:154)
UnityEditor.AssetPostprocessingInternal:PostprocessAllAssets(String[], String[], String[], String[], String[])

Unity is only able to load mdb or portable-pdb symbols. Assets/Photon/PhotonLibs/Photon3Unity3D.pdb is using a legacy pdb format.
UnityEngine.Debug:LogWarning(Object)
Microsoft.Unity.VisualStudio.Editor.VisualStudioEditor:SyncIfNeeded(String[], String[], String[], String[], String[]) (at Library/PackageCache/com.unity.ide.visualstudio@2.0.2/Editor/VisualStudioEditor.cs:154)
UnityEditor.AssetPostprocessingInternal:PostprocessAllAssets(String[], String[], String[], String[], String[])

after loading the SlotCar Demo Scene, there is another warning:
Scene 'PunCockpit-Scene' couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
To add a scene to the build settings use the menu File->Build Settings...
UnityEngine.SceneManagement.SceneManager:LoadScene(String, LoadSceneMode)
Photon.Pun.Demo.Cockpit.<Start>d__6:MoveNext() (at Assets/Photon/PhotonUnityNetworking/Demos/PunCockpit/Scripts/ThirdParty/PunCockpitEmbed.cs:53)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

If I build the Demo now as Windows Standalone, everything works fine despite the several warnings.

If I switch the platform to WebGL i get another 3 warnings:
Assets\Photon\PhotonRealtime\Code\PhotonPing.cs(449,17): warning CS0618: 'WWW' is obsolete: 'Use UnityWebRequest, a fully featured replacement which is more efficient and has additional features'

Assets\Photon\PhotonRealtime\Code\PhotonPing.cs(456,35): warning CS0618: 'WWW' is obsolete: 'Use UnityWebRequest, a fully featured replacement which is more efficient and has additional features'

Assertion failed on expression: 'ins.second || ins.first->second == targetHash || (ins.first->second == CircularDependencyHash() && !targetHash.IsValid()) || GetPathFromAssetGuidV2(key.GetGUID()).ends_with(".cs")'

now, if I click on "Build" I get another 4 messages:
Assets\Photon\PhotonLibs\WebSocket\WebSocket.cs(5,7): error CS0246: The type or namespace name 'WebSocketSharp' could not be found (are you missing a using directive or an assembly reference?)

Error building Player because scripts had compiler errors

Build completed with a result of 'Failed'
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

UnityEditor.BuildPlayerWindow+BuildMethodException: 2 errors
at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x0027c] in <d1bec46880064709a5e713ad543e6d96>:0
at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in <d1bec46880064709a5e713ad543e6d96>:0
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Do you know what is wrong? Why is unity not even able to build the Demo of PUN 2 in WebGL?
As I already said I have the newest version of Unity and PUN 2.
I hope my request is not confusing or stupid.

Comments

  • Tobias
    Options
    PhotonLibs/netstandard2.0/Photon3Unity3D.pdb is using a legacy pdb format.

    Funny. The lib was built with VS 2019 and recent SDKs.
    Might be a bug of Unity to complain but it's just a warning. You just have no debug info.

    The only real problem is that the export expects WebSocketSharp, which is definitely not used in WebGL exports.

    The issue is the code "using WebSocketSharp;", which was added to the file WebSocket.cs. If you move it to line 9 (counted before the move), the export works again.

    Sorry for the hassle.
  • Dufffit
    Options
    Tobias wrote: »
    ...
    The only real problem is that the export expects WebSocketSharp, which is definitely not used in WebGL exports.

    The issue is the code "using WebSocketSharp;", which was added to the file WebSocket.cs. If you move it to line 9 (counted before the move), the export works again.
    ...

    Thank you! That really helped. Now I am able to build the Demo in WebGL. But I am still not able to play. Unity tells me, that the Build succeeded.
    Build completed with a result of 'Succeeded'
    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

    But if I try to open it in my Browser (Firefox) I am stucked in the loading screen:
    webgl-stuck.jpg
    This happens also with Microsoft Edge.
    Other WebGL Builds without PUN are running well.
  • OneManArmy
    Options
    If you use Mozilla, then press Ctrl + Shift + K to open console.
  • Dufffit
    Options
    I get this two Error messages:

    Uncaught SyntaxError: illegal character webglbuild.framework.js.gz:1

    Uncaught ReferenceError: unityFramework is not defined
    onload file:///C:/<path>/Photondemo/webglbuild/Build/webglbuild.loader.js:1
    webglbuild.loader.js:1:3144
    onload file:///C:/<path>/Photondemo/webglbuild/Build/webglbuild.loader.js:1
  • Tobias
    Options
    This looks like an issue in the loader code. No idea why, this is Unity's domain.
    A classic issue is a "space" in the path. Avoid that.

    Maybe you check another Unity Editor version for the export?

    Also import PUN into a new, empty project and export one of our demos (with the small fix discussed above. Let us know which Unity version you run.
  • Dufffit
    Options
    I tried it with 2020.1.2f1 and also 2020.1.0f1 before.

    I also did the import into a new, empty project.

    If the problem is Unity-wise I maybe try a complete reinstallation of Unity...
  • Dufffit
    Options
    I have an update:
    I completely uninstalled Unity and installed the newest Version 2020.1.3f1.
    The Slot Car Demo has the same Problem, BUT the Asteroid Demo works now witch WebGL (I did not test the other Demos up to now... a WebGL Build just takes too much time :D)

    So it seems to be a problem of the Slot Car Demo and not a general PUN/Unity Problem. I will try to use it in my own projects now and hope that I can get it working.

    Thanks for you efforts so far!
  • Tobias
    Options
    Please copy and paste the log of the SlotCar Demo. It should work in WebGL albeit showing an Error about not being able to load a scene. This should actually be Warning-level and not a concern.

    It sounds as if WebGL builds should take place in 2019.4 instead of 2020.1...
  • Dufffit
    Options
    There are good news: Also the Slotcar Demo Scene works now. I don't know what I did wrong, but I just build it a again and now it works. So it seems reinstalling Unity and the WebSocketSharp fix helped.
    Thanks for your effort again!
  • Tobias
    Options
    Thanks for your patience and providing feedback. Glad you're making progress again.