WebGL Networking error

My team has a test environment set up, and we want to get the networking side of things working before we go any further. I cannot show the code. But to start, I added a NetworkManager and HUD to an empty game object, checked use web sockets, added a NetworkIdentity to the player prefab and made it’s movement code network aware. Upon running the client and attempting to connect to the server, I get the error “TypeError: webSocketInstances.hosts is undefined.” I feel like I’m missing something obvious; I’m pretty new to Unity in general and I’ve never used web sockets, but it sounds to me like whatever javascript object that manages the web sockets isn’t getting the host address? I guess it’s worth noting that uncheching use web sockets and running a standalone build works with no issues.

Any help is greatly appreciated!

I’m running into this same error with my project’s WebGL build, and haven’t been able to figure out why yet. Going to be doing some further debugging these next few days to hopefully narrow it down. Please report back if you figure it out!

No luck, but I managed to make a working WebGL build of Unity’s networking tutorial, just by toggling use web sockets. Not entirely sure what’s different here that could cause the issue.

Yeah, no luck here either so far, unfortunately. I’ve spent a few days trying out various build settings, Unity versions, commenting out sections of code, etc. I’m probably going to have to start from a blank new project, get the web sockets working, and then start bringing code over until I figure out what specifically is triggering this error.

Just to check a few things we may have in common:

  • What Unity version? I’m on 5.3.4f1
  • Are you using Unity Cloud Build? I have been
  • Does your project use multiple threads? I’ve read this is a problem for WebGL, though I’ve tried to limit it to just the server for running database queries
  • Are you testing in a specific browser, OS? I’m testing in Firefox on Windows 7
  • Are you using any plugins with network code? I have the Photon plugin, and I suppose it could be related in some way

I can’t think of anything else unusual my project is doing, but I suspect there’s some problematic code or setting we have in common, or else more people would be running into this.

Don’t know if this is still the case now, but back when I was looking at UNET WebGL didn’t work with the matchmaking server. It only seemed to work on LAN.

Same Unity version, no cloud build, single thread, Firefox on Windows 10, small set of assets that were added to the project for potential use, but weren’t being used. That last point got me thinking. We originally were looking at photon, and so had the PUN plugin along with whatever else is added with that. I think the folder Plugins/WebSockets may have been left by accident when we removed the assets. I removed it and the project ran correctly. Re-added the folder to check, and the error came back. Hope this works for you too!

1 Like

Awesome, this was the problem for me as well. I ended up marking the Plugins/WebSocket/WebSocket.jslib as excluded for WebGL builds, so that I could still use the plugin outside the WebGL client.

Thanks for figuring that out and reporting back, really appreciate it.