WebGL Error

I am using Unity 2021.3 and Netcode for GameObjects with the Photon Realtime Transport from github.

I have an account all set up with my app id.

When I set my target to Windows/Mac/Linux there are no errors.

I need to build this app for WebGL.

When I switch to WebGL I get the following error:

(0,0): error System.TypeLoadException: Could not load type 'Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle' from assembly 'UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.

I have posted on the Unity forums and they have no idea. I went down this rabbit hole with them about getting experimental transport and beta code, but that made it worse.

It is my understanding the the Photon Realtime Transport for NGO is supposed to already support WebGL.

Please help...

Best Answer

  • Hotshot10101
    Answer ✓

    Guess what? Looks like Unity released Netcode for GO 1.1.0. It requires updating Unity to 2021.3.14f1, but once you do the error goes away and it works!!!!

    You can close this ticket with that as the solution.

Answers

  • The problem is not our transport plugin in this case. The class Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle is not available at compile time and our transport does not even require unsafe code.

    Maybe you change the setting for "allow unsafe code" in the player settings?

    Sorry, aside from grabbing for straws, I don't have an idea how we could help.

  • At this point I think what would be most helpful from you would be to tell me a configuration that has worked. Obviously your plugin worked with WebGL at some point. Can you give me the configuration that worked?

  • Again: The Unsafe.AtomicSafetyHandle is not causing issues because of our code.

    If you build PUN 2 (with the same Realtime API and dlls in the project) for WebGL, it just works. If the problem is due to our code, it should also happen without Netcode for Game Objects.

  • I am not saying it is your code. I understand that. Sorry if I wasn't clear.

    What you replied with about "build PUN2..." for WebGL it just works, this is what I could like the details of.

    Can you point to a tutorial or instructions to "build PUN2 (with the same Realtime API and dlls in the project) for WebGL)?

    I would like to get to this point and then go from there to my project to try to figure out where the offending code / module is.

  • If you want to prove that PUN 2 works for WebGL, the best approach is to create a new, empty project and import the latest PUN 2 from the Asset Store into it. Set the AppId (in the PhotonServerSettings), select a demo scene to build (or use the build setup menu item of PUN 2) and then select WebGL as build target. Click "build and run" in the build window.

    That usually works.

  • Before I do that I would like to clarify whether PUN2 is the same as Netcode for GameObjects using the Photon Realtime Transport?

    I need to use the later and was assuming that since both Netcode and your transport are both released, they should work. Going that route doesn't include installing PUN2 from the asset store. Should this work? Can I prove it works in WebGL?

    The Netcode documentation says that in order to use Netcode on WebGL you must use a third part transport like yours.

  • I would like to clarify whether PUN2 is the same as Netcode for GameObjects using the Photon Realtime Transport?

    No it's not the same. The Realtime Transport is something separate, including Photon Realtime and a wrapper for NGO.

    You can install the latest NGO Community Contributions to get the Realtime Transport. You possibly have to set WSS as connection protocol for WebGL exports and then it should connect (of course aside from setting an AppId, etc.).

    Again, the error with unsafe code should not be due to this plugin.

    Maybe update your Unity LTS version to a later one. Try a new, emtpy project with NGO and the Community Contributions on WebGL.

  • Thank you for the clarification.

  • So I have some news and a follow up question.

    I just made a brand new project, changed the build type to WebGL and fixed the Color Space setting by changing it to Gamma.

    My goal was to do as you suggested above and create a new project and get Photon Realtime working with Netcode for Game Objects.

    As soon as I add the Netcode for Game Objects package from the Unity package manager I get the error that is the topic of this post at the top.

    So I came back here to ask how I can get a new project going and realized that what you suggested was to create a new project and import the PUN2 asset from the asset store.

    So the big question is what is the difference between the PUN2 asset from the asset store and your Transport that is supposed to work with Netcode for GameObjects that is here on github:

    I do not want to use PUN2 specifically. I want to use Netcode for Game Objects and that github link says you provide a transport that will work with it.

    I got to that github link from this one:

    You can see pretty quickly on that page that it says Netcode for Game Objects doesn't work with WebGL UNLESS you use one of the transports from third parties that are listed in the "here" link:

    That link shows Photon Realtime and that link takes you to the one above. So here we are full circle.

    My question is:

    Do you have an example of using that transport with Netcode for Game objects that works with WebGL?

    If so can you point me to it?

  • Hotshot10101
    Answer ✓

    Guess what? Looks like Unity released Netcode for GO 1.1.0. It requires updating Unity to 2021.3.14f1, but once you do the error goes away and it works!!!!

    You can close this ticket with that as the solution.