I am using Unity 2022.2.2f1 and Entities package com.unity.entities@1.0.0-pre15, which is supposed to be production ready and supported across all platforms.
So I implemented it into one of my projects and have been developing on Windows without any problems. But later on I tried deploying it as a Dedicated Server for Linux and also WebGL - but whenever I click the “Build” button and pick the destination directory, the Entities package immediately throws a NullReferenceException:
NullReferenceException: Object reference not set to an instance of an object
Unity.Scenes.Editor.EntitySceneBuildPlayerProcessor.HandleGetBuild (UnityEditor.BuildPlayerOptions opts)
(at ./Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Scenes.Editor/EntitySceneBuildPlayerProcessor.cs:71)
The problem seems to come from the EntitySceneBuildPlayerProcessor.cs file at line 71 - this is the relevant method where it fails: (it fails because the ServerProvider is NULL)
static BuildPlayerOptions HandleGetBuild(BuildPlayerOptions opts)
{
opts = BuildPlayerWindow.DefaultBuildMethods.GetBuildPlayerOptions(opts);
var instance = DotsGlobalSettings.Instance;
if (instance.GetPlayerType() == DotsGlobalSettings.PlayerType.Server)
{
// IT FAILS HERE (ServerProvider is NULL)
opts.extraScriptingDefines = instance.ServerProvider.GetExtraScriptingDefines();
// Adding EnableHeadlessMode as an option will switch the platform to dedicated server that defines UNITY_SERVER in the Editor as well.
// We may want to switch back to the original platform at the end of the build to prevent it if we don't support switching to dedicated server.
// Currently the Editor fails to compile after switching to the dedicated server subtarget.
opts.options |= instance.ServerProvider.GetExtraBuildOptions();
}
else
{
opts.extraScriptingDefines = instance.ClientProvider.GetExtraScriptingDefines();
opts.options |= instance.ClientProvider.GetExtraBuildOptions();
}
return opts;
}
The weird thing to me is that “GetPlayerType()” returns “Server” even for WebGL platform, causing it to fail as well. So I tried making the Entities package local and editing this part of the method by treating it as a Client always - but this causes the whole Editor to crash with a C++ runtime error.
Tried restarting Unity and also building on different PCs - tried deleting cache and downloading all packages again. Also tried manually adding certain build symbols to Player settings like “UNITY_CLIENT” or “UNITY_SERVER” in hopes to change the behaviour, but nothing changed.
I am not using Netcode at all - if that is maybe relevant. I am only using Entities and Entities Physics.
Entities still is in preview so it not completely production ready yet.
As for WebGL it is not supported by the hybrid renderer (entities.graphics). Some features are missing from WebGL and unity is waiting on WebGPU to support them to iclude that support for DOTS.
My project does not use or even include entities.graphics. And yes - based on the latest news, and their samples - it should work on WebGL and also on dedicated servers
We also have issues with ECS and WebGL, but it’s somewhat different. We are using 2022.2.4 and entities 1.0.0-pre.15. The game builds and runs in the browser, but we get runtime errors trying to load ECS data. It seems to be trying to load from StreamingAssets using standard file IO. So either we need a way to build data to a different location, or some way to fix the loading. We get the same errors even with the HelloCube ECS sample.
“To make this easier to achieve, we’ve included a small sample to illustrate how users can use ECS and build to WebGL” - has anyone seen this sample? I don’t see anything like this in the ECS samples.
After upgrading my project to Unity 2023.1.0b2, I can now successfully build for WebGL using Entities. However, I can NOT build for Dedicated Server (same issue as before).
Took noticably longer to build now; the “Linking build.js” step took more than 1.7 hours for my first build - I’m hoping the next builds are shorter (was ~14min before)
The reason I upgraded, however, was related to another bug in Unity 2022.2.0f5 that just appeared out of nowehere one day, which was my URP 2D renderer asset disappearing when launching Unity, having to re-create it every time - but often it also broke building the project for even Windows. Either way, upgrading to 2023.1 fixed both issues for me.
Didn’t expect a Beta to be more stable than a Final release for my project, but alas, here we are.
Well, at the moment everything works, so I’m staying where I am. But thanks for the warning - will probably wait a bit before upgrading to a more stable version.
Though still waiting for a fix for the Dedicated Server build…
Add the com.unity.netcode package. This will include a DotsPlayerSettingsProvider with a Server player type and allow the build to continue when Dedicated Server build target is choosen. There looks to be a way to add your own provider but didnt look too deep into that. Its a little silly if you want to use Entities but building for a traditional multiplayer game without the netcode package.
/// <summary>
/// The baking settings for the default entities setup.
/// </summary>
/// <remarks>The com.unity.netcode package will add more settings for different build targets.</remarks>
[FilePath("ProjectSettings/EntitiesClientSettings.asset", FilePathAttribute.Location.ProjectFolder)]
internal class EntitiesClientSettings : ScriptableSingleton<EntitiesClientSettings>, IEntitiesPlayerSettings
Nice find, this explains why the “GetPlayerType” returns “Server” even for WebGL platform. I guess they never tested it without Netcode. Definitely a bug then.
@CryShana does your webgl build work with bakers? I have ecs webgl + dedicated server working together but I am unable to use subscenes (and consequently bakers).