Can't build for Dedicated Server Linux and WebGL when using Entities 1.0.0-pre.15

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.

1 Like

Same here, just an empty 2022.2.2f1 project with Entities installed, set Build Target to Dedicated Server (Windows), and build failure

edit: same with 2022.2.1f1

Any fix for this?

Tried with Unity 2022.2.3f1 as well, same problem. Seems to really be the Entities package problem.

1 Like

Has anyone submitted a bug report? I haven’t but I can if no one else wants to

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.

Supposedly theres a way to do Entites WebGL without Entities Graphics, but in my experience the sample/exampe in github didn’t work

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

Same with 2022.2.4
I submitted a bug report

Edit: I submitted about building to dedicated server, but not about webgl
CASE IN-30223

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.

I believe they’re talking about the GameObject Sync example, they call it a “generic” sample so maybe they never actually tested it with webgl

EntityComponentSystemSamples/EntitiesSamples/HelloCube/Assets/8. GameObjectSync at master · Unity-Technologies/EntityComponentSystemSamples (github.com)

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.

Don’t go in expecting 2023.1 to keep working.

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…

Does it also successfully run? The HelloCube ECS sample still doesn’t seem to work in 2023.1.0b2.

I submitted a bug report. Tested the HelloCube sample on 2022.2.0, 2022.2.4 and 2023.1.0b2 with the same result.

1 Like

Upgraded project to 2022.2.5 and also ran into this bug when trying to build for Dedicated Server for Windows

Found a fix!

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
2 Likes

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.

1 Like

@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).