Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Subscenes aren't built

Discussion in 'NetCode for ECS' started by MrEastwood, Aug 25, 2021.

  1. MrEastwood

    MrEastwood

    Joined:
    Dec 9, 2013
    Posts:
    19
    I'm trying to create a DOTS multiplayer project and I'm following the way the multiplayer samples work by putting a ghost collection in a subscene. It works in the editor but not in builds. I've searched the forums and tried what I found but so far no luck. I get the "Failed to read from [path]/StreamingAssets/SubScenes/[hash].entityheader" error and indeed those files don't exist. The entire SubScenes folder is missing from the build's StreamingAssets folder. I've tried building the Asteroids example project and that works, but I haven't found the difference yet. Things I've tried:
    • I'm using the configurable build pipeline to make the build. I'm using a classic Windows build profile.
    • I've read that you don't need to include the subscene in the scene list. Tried to include it anyway or leave it out and in either case the subscene is not built.
    • I'm not using the UI Toolkit package or any addressables.
    • I did install the windows platform package (version 0.10.0-preview.10) and I verified that it also included the platforms package.
    • I'm using a custom bootstrap as described in the manual https://docs.unity3d.com/Packages/com.unity.netcode@0.6/manual/client-server-worlds.html#bootstrap, but since this is code it shouldn't mess with resources being built.
    • I'm using Unity 2020.3.16f1, but I've tried several 2020 versions with the same result.
    • I'm using the hybrid renderer package 0.11.0-preview.44 and the dependencies it pulls in.
    Since the Asteroids example does work with subscenes in the build I know it's not a bug in Unity. I even upgraded the Asteroids packages to the exact versions I'm using in my project and that works too, but I don't know what to try next to get my subscenes to build. Any suggestions will be much appreciated!
     
    Last edited: Aug 25, 2021
  2. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    774
    You should not include the sub-scene to the scene list of the build configuration. They are automatically added to the the build by walking the the GameObject SubScene components present in the root scene.

    The problem is not the bootstrap or Netcode, but rather some setup of the build configuration you currently have. Can you please share more about how you configured your scene, and the build pipeline (some picture may help)
     
  3. MrEastwood

    MrEastwood

    Joined:
    Dec 9, 2013
    Posts:
    19
    As these things go, after you ask for help an idea pops up that turned out to be the solution for me :p
    TLDR: The subscene wasn't built because I had disabled the subscene component.

    I delay the creation of server and client worlds because I want to give users the option to host or join a LAN game. I haven't figured out how to do this properly but the workaround I found is that if you disable the subscene component and leave autoload checked, then the entities will be loaded in the server and client worlds if you enable the subscene component after you create them. With autoload off I didn't know how to load it after the worlds were created. I looked at the source for the subscene component and it looked like OnEnable does what I want (specifically calling AddSceneEntities) and I didn't see another way to do it.

    At least now I know disabling the component is not the way to do it since that will prevent the scene from ending up in the build. One problem solved, and one to go :p
     
  4. MrEastwood

    MrEastwood

    Joined:
    Dec 9, 2013
    Posts:
    19
    In case someone is wondering how to load the subscene on demand, this is how I ended up doing it:
    Code (CSharp):
    1. void loadSubScene()
    2. {
    3.    foreach (var world in World.All)
    4.    {
    5.        SceneSystem sceneSystem = world.GetExistingSystem<SceneSystem>();
    6.        if (sceneSystem != null)
    7.        {
    8.            Entity sceneEntity = sceneSystem.LoadSceneAsync(SubScene.SceneGUID);
    9.            sceneSystem.EntityManager.AddComponentObject(sceneEntity, this);
    10.        }
    11.    }
    12. }
    Note: I have a variable called SubScene (so this is not some static field of the SubScene class) which references the subscene that holds the scene reference I want to load. This is basically what
    AddSceneEntities()
    does except I leave out the flags. It feels a bit dirty to have to copy a piece of code, so I hope at some point a public method will be added to SubScene that does this on demand, something like
    LoadSceneNow()