Skip to content

Instantly share code, notes, and snippets.

@travelhawk
Last active January 28, 2021 16:07
Show Gist options
  • Save travelhawk/fd0fa8a034fa2cc325e37e3e9e4f1ed8 to your computer and use it in GitHub Desktop.
Save travelhawk/fd0fa8a034fa2cc325e37e3e9e4f1ed8 to your computer and use it in GitHub Desktop.
Porting a desktop unity application to a webgl build

Porting to WebGL in Unity3D

Porting from Desktop / UWP to WebGL comes with a lot of challenges. When I ported an application, there were many libraries and code which didn't work on WebGL. However, I found alternatives and were able to switch libraries to make it work in WebGL.

Not supported features

  • System.Net namespace
  • Threads are not supported (System.Threading)
  • No Multithreading
  • No direct access to socket
  • Reflection using System.Reflection.Emit
  • WebGL graphics limitations

Used libraries before porting which didn't work

  • Websocket: System.Net.WebSockets
  • GLTF: UnityGLTF
  • JSON: Newtonsoft.Json
  • HTTP Request: CI.HttpClient

Solutions

Websockets

For websockets, I switched to https://github.com/endel/NativeWebSocket

GLTF

For gltf support, I switched to https://github.com/atteneder/glTFast

JSON

For json support, I switched to https://github.com/jilleJr/Newtonsoft.Json-for-Unity

If your code doesn't depend much on Newtonsoft.JSON, an alternative is to use Unity's builtin json support

HTTP requests

For http requests, I switched to Unity's builtin UnityWebRequest

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment