Just starting to experiment with NetCode for ECS, which means I have an almost empty project, and just wanted to create a WebGL build and a Dedicated Linux Server build and see if I can get the two connecting.
But when I open up the WebGL build in a browser, it fails to load and I get this error in the console:
NotSupportedException: Creating a server driver for a WebGL build is not supported. You can’t listen on a WebSocket in the browser. WebGL builds should be ideally client-only (has UNITY_CLIENT define) and in case a Client/Server build is made, only client worlds should be created.
at Unity.NetCode.IPCAndSocketDriverConstructor.CreateServerDriver (Unity.Entities.World world, Unity.NetCode.NetworkDriverStore& driverStore, Unity.NetCode.NetDebug netDebug) [0x00000] in <00000000000000000000000000000000>:0
And a print screen of the browser console that shows my custom server bootstrap is getting initialised:
Of course, a WebGL build should only have client systems running, and no attempts to listen should be made, but how do I ensure that?
As per the error message, I’ve added UNITY_CLIENT
to the scripting defines for the WebGL build, just in case Unity doesn’t do that for me:
I’ve also got the NetCode Client Target set to ‘Client’, not ‘ClientAndServer’:
Getting a bit desperate I went and wrapped my custom bootstrap and WorldSystemFilterFlags.ServerSimulation system in #if !UNITY_WEBGL
:
#if !UNITY_WEBGL
class MyCustomClientServerBootstrap : ClientServerBootstrap {
public override bool Initialize(string defaultWorld) {
bool result = base.Initialize(defaultWorld);
var customTickRate = new ClientServerTickRate(); //run at 30hz
customTickRate.SimulationTickRate = 15;
customTickRate.ResolveDefaults();
foreach (var world in World.All) {
if (world.IsServer()) {
//In this case we only create on the server, but we can do the same also for the client world
var tickRateEntity = world.EntityManager.CreateSingleton(new ClientServerTickRate { SimulationTickRate = 30 });
}
}
return result;
}
}
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
public partial class TheServerUniverse : SystemBase {
}
#endif
But still no luck. My Unity WebGL build still loves to try and bootstrap a ClientServerBootstrap object.
(If I run the client-only in the Editor I can connect to my Linux dedicated server just fine.)
What am I doing wrong? What am I missing? As you can see, there’s not a lot of C# here, is there another build or player setting I’ve overlooked?