magicblock-labs / Solana.Unity-SDK

Open-Source Unity-Solana SDK with Full RPC coverage, NFT support and more
https://solana.unity-sdk.gg
MIT License
160 stars 89 forks source link

[Bug] websocket-sharp shipped with Solana SDK breaks WebGL multiplayer games #227

Closed PinoEire closed 3 months ago

PinoEire commented 3 months ago

Describe the bug Adding this SDK to a working WebGL multiplayer game breaks it because of the version of websocket-sharp shipped with it.

To Reproduce Add this to a working WebGL multiplayer game built with Unity Netcode for GameObjects or Fusion 2.

Expected behaviour One would expect the game to keep working.

Screenshots screenshots to help explain the problem.

Desktop (please complete the following information):

GabrielePicco commented 3 months ago

@PinoEire, can you please specify if the issues are compilation or runtime? Which version of websocket-sharp are you removing to resolve the conflict?

This issue resolution could be helpful: https://github.com/magicblock-labs/Solana.Unity-SDK/issues/148#issuecomment-1646606832 (for the Multiplay package), but I haven't tried it with Fusion.

If you have a minimal repository to reproduce the issue, I can help investigate.

PinoEire commented 3 months ago

@GabrielePicco I did try that solution, which is the one that removes the build errors (naturally) but it also causes other SDK (Fusion and Unity NGO) to try using your version, which is somehow different and ar runtime the game in the browser issues the error:

Invoking error handler due to TypeError: instance.ws is undefined _WebSocketClose@https://...

Apparently there is no way around because I can't find a way to remove your version of websocket-sharp without breaking the build and your version is breaking the WebGL multiplayer.

PinoEire commented 3 months ago

@GabrielePicco You can easily reproduce this using the Fusion 2 Asteroid Sample.

GabrielePicco commented 3 months ago

The root of the issue is that there is no great way to do dependency management in Unity, as far as I know. The SDK uses a version that is apparently different from the one used in Fusion and NGO.

As far as I know, WebSocket Sharp does not work on WebGL.

The solution adopted in the SDK is to use a wrapper: https://github.com/magicblock-labs/NativeWebSocket which uses NativeWebSocket when building for WebGL and websocket-sharp when building for other platforms.

I'm not entirely sure which version of websocket-sharp Fusion and NGO use or where they use it. Can you please provide a minimal repo to reproduce this issue? That would help in investigating a potential solution.

PinoEire commented 3 months ago

OK @GabrielePicco I'll make available the Fusion 2 Asteroids sample in the form of a GitHub repo with Solana SDK imported.

PinoEire commented 3 months ago

Hi @GabrielePicco, sorry for the late post, but I've been busy solving this issue. It comes out that Solana SDK is only transversely responsible for the problem, adding to the WebGL network buffer so that adding the SDK makes the problem stick out sooner, but it's not your fault.

The problem is the number of Network Objects in the scene, which Unity Transport (and Fusion) cannot cope with in WebGL. For some reason. Sorry for pointing at you 😅

GabrielePicco commented 3 months ago

Glad you found the cause!

GabrielePicco commented 1 month ago

@PinoEire, it's been a while. Would you mind updating your review on the Unity Asset Store?

https://assetstore.unity.com/packages/decentralization/infrastructure/solana-sdk-for-unity-246931#reviews

PinoEire commented 1 month ago

@PinoEire, it's been a while. Would you mind updating your review on the Unity Asset Store?

https://assetstore.unity.com/packages/decentralization/infrastructure/solana-sdk-for-unity-246931#reviews

Sorry, I totally forgot that! It is done 😊.