Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

Discussion in 'Entity Component System' started by CryShana, Jan 17, 2023.

  1. CryShana

    CryShana

    Joined:
    Nov 30, 2013
    Posts:
    12
    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)

    Code (CSharp):
    1. static BuildPlayerOptions HandleGetBuild(BuildPlayerOptions opts)
    2. {
    3.     opts = BuildPlayerWindow.DefaultBuildMethods.GetBuildPlayerOptions(opts);
    4.     var instance = DotsGlobalSettings.Instance;
    5.  
    6.     if (instance.GetPlayerType() == DotsGlobalSettings.PlayerType.Server)
    7.     {
    8.         // IT FAILS HERE (ServerProvider is NULL)
    9.         opts.extraScriptingDefines = instance.ServerProvider.GetExtraScriptingDefines();
    10.        
    11. // Adding EnableHeadlessMode as an option will switch the platform to dedicated server that defines UNITY_SERVER in the Editor as well.
    12.         // 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.
    13.         // Currently the Editor fails to compile after switching to the dedicated server subtarget.
    14.         opts.options |= instance.ServerProvider.GetExtraBuildOptions();
    15.     }
    16.     else
    17.     {
    18.         opts.extraScriptingDefines = instance.ClientProvider.GetExtraScriptingDefines();
    19.         opts.options |= instance.ClientProvider.GetExtraBuildOptions();
    20.     }
    21.     return opts;
    22. }
    23.  
    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.
     
    BackgroundMover likes this.
  2. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    216
    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
     
    Last edited: Jan 21, 2023
  3. Diego-Programmer

    Diego-Programmer

    Joined:
    Dec 10, 2015
    Posts:
    2
    Any fix for this?
     
  4. CryShana

    CryShana

    Joined:
    Nov 30, 2013
    Posts:
    12
    Tried with Unity 2022.2.3f1 as well, same problem. Seems to really be the Entities package problem.
     
    BackgroundMover likes this.
  5. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    216
    Has anyone submitted a bug report? I haven't but I can if no one else wants to
     
  6. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    988
    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.
     
  7. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    216
    Supposedly theres a way to do Entites WebGL without Entities Graphics, but in my experience the sample/exampe in github didn't work
     
  8. CryShana

    CryShana

    Joined:
    Nov 30, 2013
    Posts:
    12
    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
     
  9. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    216
    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
     
    Last edited: Mar 9, 2023
  10. chris1P

    chris1P

    Joined:
    Aug 20, 2013
    Posts:
    27
    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.
     
  11. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    216
    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)
     
  12. CryShana

    CryShana

    Joined:
    Nov 30, 2013
    Posts:
    12
    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.
     
    Last edited: Feb 3, 2023
  13. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    510
    Don't go in expecting 2023.1 to keep working.
     
  14. CryShana

    CryShana

    Joined:
    Nov 30, 2013
    Posts:
    12
    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...
     
  15. chris1P

    chris1P

    Joined:
    Aug 20, 2013
    Posts:
    27
    Does it also successfully run? The HelloCube ECS sample still doesn't seem to work in 2023.1.0b2.
     
  16. chris1P

    chris1P

    Joined:
    Aug 20, 2013
    Posts:
    27
    I submitted a bug report. Tested the HelloCube sample on 2022.2.0, 2022.2.4 and 2023.1.0b2 with the same result.
     
    BackgroundMover likes this.
  17. kmowers

    kmowers

    Joined:
    Dec 12, 2016
    Posts:
    15
    Upgraded project to 2022.2.5 and also ran into this bug when trying to build for Dedicated Server for Windows
     
  18. kmowers

    kmowers

    Joined:
    Dec 12, 2016
    Posts:
    15
    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.


    Code (CSharp):
    1. /// <summary>
    2.     /// The baking settings for the default entities setup.
    3.     /// </summary>
    4.     /// <remarks>The com.unity.netcode package will add more settings for different build targets.</remarks>
    5.     [FilePath("ProjectSettings/EntitiesClientSettings.asset", FilePathAttribute.Location.ProjectFolder)]
    6.     internal class EntitiesClientSettings : ScriptableSingleton<EntitiesClientSettings>, IEntitiesPlayerSettings
     
    linfuqing and BackgroundMover like this.
  19. CryShana

    CryShana

    Joined:
    Nov 30, 2013
    Posts:
    12
    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.
     
    kmowers likes this.
  20. chefneil

    chefneil

    Joined:
    Aug 21, 2020
    Posts:
    29
    @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).
     
  21. CryShana

    CryShana

    Joined:
    Nov 30, 2013
    Posts:
    12
    Yeah I have bakers in my scene and it builds for WebGL - but I haven't been able to try it out with my server yet because the server doesn't build at all. I put my project on hold for time being until this gets fixed.
     
  22. chefneil

    chefneil

    Joined:
    Aug 21, 2020
    Posts:
    29
    Ok heads up - your build may work but it's likely that your subscenes/bakers will not work on the frontend. For me, this can be demonstrated on the most simple, non netcode, ecs projects.
     
  23. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    216
    From the Entities 1.0.0-pre.44 changelog

    (Fixed)
    • Crash when building a Dedicated Server and Netcode package not present.
     
  24. CryShana

    CryShana

    Joined:
    Nov 30, 2013
    Posts:
    12
    I updated Unity to 2023.1.0b4 and both Entities and Entities.Physics to pre.44 - the previous error is now gone for Dedicated Server for Linux, however now right after clicking Build, I immediately get the following error:



    This is the same error I got when I first tried bypassing the original error.

    I will probably try this again after cleaning up the project a bit and maybe also on a fresh project later to see if the issue persists.

    (I have also built for Standalone Windows and ran it in Editor - and both worked fine - haven't tried WebGL yet with the updated Entities)

    (I tried building for Windows server now instead, same runtime error - so I guess Linux doesn't matter)
     
    Last edited: Feb 18, 2023
    BackgroundMover likes this.
  25. CryShana

    CryShana

    Joined:
    Nov 30, 2013
    Posts:
    12
    Yeah, nevermind - creating a fresh project using 2023.1.0b4 and then adding Entities package to it, doesn't work - won't compile. I'm guessing this relates to the official post that ECS is not yet fully supported on 2023 betas... which is understandable.

    But it surprises me that my other project that was upgraded to 2023.1.0b4 works everywhere but the server platform.

    Well, I am in no rush, so I can wait for them to make ECS fully work with 2023 Unity first - and will then try again.
     
  26. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    216
    The latest hotfix didn't seem to fix it

    Still present in 2022.2.11f1
     
    Last edited: Mar 16, 2023
  27. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    216
    Case IN-30223 is marked "Under review"
     
    kmowers and CryShana like this.
  28. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    216
    WebGL successfully builds and runs a system!
    With 2022.2.12f1 and Entities 1.0.0-pre.65

    Edit: I guess there are caveats that subscenes and burst don't work with WebGL ECS:
    Windows Dedicated Server build no longer crashes the editor,
    however, building fails with
    Code (CSharp):
    1. Library\Bee\artifacts\WinPlayerBuildProgram\AsyncPluginsFromLinker: burst-lld-14-hostwin: error: undefined symbol: burst.initialize.externals.d9eb3679754ab10c8d46a1d477bf7930_x64_sse2
     
    Last edited: Mar 28, 2023
    CryShana likes this.
  29. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    216
  30. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    216
    Success with building and running a dedicated server in 2022.2.13f1 with Entities 1.0.0-pre.65
    Woot!

    Edit: when trying to Debug.Log() a ComponentType, it prints out as Null, but they still seem to function in systems
     
    Last edited: Apr 10, 2023
    CryShana and kmowers like this.