- Home /
Is it possible to get a networked WebGL build to run in single player mode?
I'm building a game (using Unity Networking) that should be playable solo or with friends. I will be launching on PC/Mac, but I'd like to make a WebGL build in the meantime for easier playtesting. It builds fine and, using Websockets, I can connect to the host running in the editor. The Network Manager HUD won't let my WebGL build start the game as a Host though. I am fine with the WebGL build not being able to accept incoming connections, but is it possible to get it running as a Host and just not be able to have friends join?
I've attempted to manually start the game using Network$$anonymous$$anager.StartHost() ins$$anonymous$$d of the Network $$anonymous$$anager HUD, but this doesn't work. No errors are thrown in the browser console, it just doesn't start up properly so my player prefab never gets instantiated, etc. (this does work to start the game in the editor)
The only WebGL option I've been able to get working is connecting as a Client to localhost while I have the editor or another build running as the Host. It won't even use the $$anonymous$$atchmaker. So is a dedicated server required to run a WebGL build that uses Unity Networking?
I've also tried writing some platform specific code along the lines of:
if(Application.platform == RuntimePlatform.WebGLPlayer) {
GetComponent<Network$$anonymous$$anager>().enabled = false;
}
in the hopes that the other networking components would just not do anything while the Network$$anonymous$$anager is disabled. Unfortunately, ins$$anonymous$$d the NetworkIdentities go and disable the game objects that they are on, breaking my game.
EDIT: the docs say this is by design. network identities automatically disable the game object they're added to until the network manager tells them it's time to spawn in the scene
Answer by pawell · Dec 26, 2017 at 03:12 PM
I had similar problem. Starting from Unity 5.3.1 it is possible to set NetworkServer.dontListen. This flag can be used to start host in WebGL build with NetworkManager.StartHost().
Disabling server listening is enough because the only problem with starting server in WebGL build is failure to listen on any port (tested in Unity 5.6 and 2017.2). I was ready to modify Unity Networking to accomplish this but it wasn't necessary. This solution doesn't work with Network Manager HUD.
Answer by Schubkraft · Jun 13, 2016 at 12:28 PM
WebGL can't run as host. Sorry, but that is a limitation of the platform.