- Home /
I am trying to create an online multiplayer game, but UnityEngine.Networking isn't supported with WebGL exports. What would be the best way to create a networked game for WebGL?
I have a game that I posted on my website as a WebGL export. But the problem is that its a networked game, where all the scripts use the class UnityEngine.Networking. After I posted the game I found out that WebGL can't create servers... No Problem, so I created a server, after that I couldn't join my server. After some research I found out that WebGL dose not support UnityEngine.Networking. What would be the best approach to creating this game where it would work with a WebGL export (Preferably where WebGL User can also host the server).
Answer by softrare · May 10, 2018 at 08:07 PM
UnityEngine.Networking does work with WebGL, only you need to activate it on the NetworkManager (WebSockets). And note, that you cannot connect with any other client platform than WebGL if you do activate it.
Hosting a server is impossible though with WebGL, you have to make the server dedicated.
EDIT: Just corrected the last sentence where it said "Hosting a server is impossible with WebSockets enabled". That can be confusing as it is possible to have WebSockets enabled and hosting a server surely, but not WHILE you're running a WebGL build in a web browser.
Ok, thanks for the advice. But I have a few questions about this... First of all I don't know what a dedicated server is. And I have read a few articles that talk about dedicated servers, but I know what one is, much less how to set one up.
Is there an article that could explain this to me?
Thanks for you help so far.
A dedicated server in this case is a game server ideally running 24/7 on a dedicated server machine which in most cases is not a personal computer but a virtual or physical server in a datacenter. So in ga$$anonymous$$g networks we speak of a dedicated server as opposed to a "host" which would just be a server being run for the amount of time a game is played and where the server player himself spawns a character and particitpates in the game play as client as well. A dedicated server only waits for other players from the Internet to connect to it, but does not spawn itself a player because noone is actively "sitting in front of it" to play.
I am author of the Unity asset u$$anonymous$$$$anonymous$$O (http://u3d.as/6hQ) which is specifically optimized for dedicated servers and uses UNet under the hood, so that you can still make use of all things and exact syntax from UNet, also using the Network$$anonymous$$anager you know from it. From next version on it will be possible to use the WebSockets as well, I have that working in my dev version already. I also provide relatively cheap dedicated but powerful servers for rent, including all kinds of assistence you could be needing with running them, file upload, security, server restarts, ect.
I've seen a Unity owned, online cloud server host called photon. Would that online cloud host meet the requirements of my game.