Search Unity

Question How do I build windows 32bit with BuildConfiguration files

Discussion in 'Entity Component System' started by SLGSimon, Apr 11, 2021.

  1. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    80
    The "Classic Build Component" uses a platform list that includes Windows but only as 64bit standalone. How do I build 32 bit standalone?

    Having been forced to use this new system with entities 0.17 means:
    * We can't upgrade our packages
    * We can't upgrade our unity version

    Also the lack of documentation for this required change has been incredibly frustrating.

    Even more so when the reason giving is subscene processing, and we don't even use subscenes.
     
    andreiagmu likes this.
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    We build fine with Unity 0.17 without the new build configuration.

    I assume you're failing from something like "The scene catalog has not been loaded yet"?

    Just make your bootstrap stop SceneSystem from being added to your world.
     
    SLGSimon likes this.
  3. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    80
    We get a crash when using IL2CPP, as part of
    AutomaticWorldBootstrap
    . Perhaps we can just disable the bootstrap, but I'm not sure that's a "supported" scenario with ECS moving forward...
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Code (CSharp):
    1.     static class AutomaticWorldBootstrap
    2.     {
    3.         [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    4.         static void Initialize()
    5.         {
    6.             DefaultWorldInitialization.Initialize("Default World", false);
    7.             GameObjectSceneUtility.AddGameObjectSceneReferences();
    8.         }
    9.     }
    Where AddGameObjectSceneReferences

    Code (CSharp):
    1. public static void AddGameObjectSceneReferences()
    2. {
    3.     foreach (var world in World.All)
    4.     {
    5.         var sys = world.GetExistingSystem<SceneSystem>();
    6.         if (sys != null)
    7.         {
    8.             for (int i = 0; i < SceneManager.sceneCount; i++)
    9.             {
    10.                 // TODO: https://unity3d.atlassian.net/browse/DOTS-3329
    11.                 var scene = SceneManager.GetSceneAt(i);
    12.                 var guid = sys.GetSceneGUID(scene.path);
    13.                 if (guid.IsValid)
    14.                 {
    15.                     // This does not actually load the scene, as it will detect the scene is loaded
    16.                     // and just add a reference
    17.                     LoadGameObjectSceneAsync(sys, guid, default);
    18.                 }
    19.             }
    20.         }
    21.     }
    22. }
    So if SceneSystem doesn't exist (as I suggested) it doesn't do anything.
     
    SLGSimon likes this.
  5. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    80
    When you say "Just make your bootstrap stop SceneSystem from being added to your world." What bootstrap are you referring to if not this one?
     
  6. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Your ICustomBootstrap implementation and if you don't have one, well you'll be the first I've seen not use it!
     
    SLGSimon likes this.
  7. Rupture13

    Rupture13

    Joined:
    Apr 12, 2016
    Posts:
    131
    When implementing the ICustomBootstrap interface, the default DefaultWorldInitialization is skipped in favour of using the custom bootstrap initialisation. So your custom bootstrap script is used if it exists (which Unity finds through reflection), else Unity just uses the default initialisation.

    I found the documentation on creating a custom bootstrap a bit tough, as parts of it are outdated.
    For example, the part in the manual states the interface as:
    Code (CSharp):
    1. public interface ICustomBootstrap
    2. {
    3.     // Returns the systems which should be handled by the default bootstrap process.
    4.     // If null is returned the default world will not be created at all.
    5.     // Empty list creates default world and entrypoints
    6.     List<Type> Initialize(List<Type> systems);
    7. }
    while in actuality the interface is:
    Code (CSharp):
    1. public interface ICustomBootstrap
    2. {
    3.     bool Initialize(string defaultWorldName);
    4. }

    I'd advise looking at the
    DefaulWorldInitialization.cs
    script and copy the code that you need for your custom bootstrap script from that. That's what has worked for me.
     
    SLGSimon likes this.
  8. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    80
    I was able to get it to work, but I had to remove a bunch of systems that were pulling in
    SceneSystem
    (I also had to do it by name as some are private, but it also means I don't need an extra dependency on Unity.Scenes):

    Code (CSharp):
    1.  
    2.     public class EcoBootstrap : ICustomBootstrap
    3.     {
    4.         string[] bannedSystems = new[] {
    5.             "SceneSystem",
    6.             "GameObjectSceneSystem",
    7.             "ResolveSceneReferenceSystem",
    8.             "SceneSectionStreamingSystem",
    9.             "SceneSystemGroup",
    10.             "LiveLinkResolveSceneReferenceSystem",
    11.             "EditorSubSceneLiveLinkSystem"
    12.         };
    13.         /// <summary>
    14.         /// Initialise a game world, overriding Unity's default.
    15.         /// </summary>
    16.         /// <param name="defaultWorldName">world name provided by unity ("Default World")</param>
    17.         public bool Initialize(string defaultWorldName)
    18.         {
    19.             Debug.Log("start of EcoBootstrap.Initialize");
    20.  
    21.             var world = new World(defaultWorldName, WorldFlags.Game);
    22.             World.DefaultGameObjectInjectionWorld = world;
    23.  
    24.             var systemList = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default, false);
    25.  
    26.             // remove SceneSystem to stop AutomaticWorldBootstrap from trying to load non-existant scene data.
    27.             var newList = systemList.ToList().Where(t => !bannedSystems.Contains(t.Name)).ToList();
    28.             DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, newList);
    29.  
    30. #if !UNITY_DOTSRUNTIME
    31.             ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(world);
    32. #endif
    33.  
    34.             Debug.Log("end of EcoBootstrap.Initialize");
    35.             return true;
    36.         }
    37.     }
    38.  
     
  9. Rupture13

    Rupture13

    Joined:
    Apr 12, 2016
    Posts:
    131
    This does indeed look very similar to how I implemented it.

    One heads up, though; I found there was an issue with world/system initialisation in builds (it worked fine in editor) if I didn't include
    TypeManager.Initialize();
    at the start of the Initialize method of the CustomBootstrap. I think the DefaultWorldInitialization.GetAllSystems depends on that. So if you were to experience a similar issue, you might want to try that ;)
     
    SLGSimon likes this.
  10. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    80
    I did experience that, once. I compared my code to what the default bootstrap was doing but couldn't find anything, and then I never got it again. I assume it was something to do with the editor.
     
    Rupture13 likes this.
  11. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    It happens from time to time. In my case simply re-importing Entities package folder resolves this.
    Adding TypeManager.Initialize does not unfortunately.

    Probably something is being corrupted e.g. from incorrect system codegen.
     
  12. andreiagmu

    andreiagmu

    Joined:
    Feb 20, 2014
    Posts:
    175
    In my case, I guess I need to use the BuildConfig system, as I use subscenes in my project.
    Is there any way to build Windows 32-bit Standalone with BuildConfig?