Search Unity

Best workflow for subscene-like loading?

Discussion in 'Entity Component System' started by CodeBison, Jul 9, 2019.

  1. CodeBison

    CodeBison

    Joined:
    Feb 1, 2014
    Posts:
    289
    I'm working on a project that uses heavily tool-assisted design processes. As part of this, editor tools assemble scene contents, including a collection of designer-specified prefab placements. I'd like to convert this to use native storage formats in line with the new subscene workflow. I've taken a quick look at the innards of things like EditorEntityScene.WriteEntityScene(), and I'm confident I can put together editor tools to automatically create SubScene components as needed. However, as the project contains a continually-growing list of assets for different levels that get streamed into the main scene on level start, I'd like to avoid having subscene components for all levels progressively filling the main scene with unnecessary objects if possible. I'd far prefer to just pull in pre-baked chunks of content as needed, without an in-scene reference being required. Is there a straightforward way to do this?

    Thanks!
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    You don't have to use subscenes.

    You can just separate all your work into separate scenes and load the scenes via code as required. Your main scene might well just be empty.

    I actually like this approach as you can make it so any scene you have active in editor is the scene that loads (for example, if each of your levels is a difference scene makes testing them individually easier without having to write any custom tools)

    Subscenes can be better for really large worlds where you want to break them into parts and stream them in as you move around etc.

    Hell you can also you can ditch the idea of scenes all together and just use prefabs.

    Really just depends on your type of game and your preferred workflow.
     
    Last edited: Jul 9, 2019
  3. CodeBison

    CodeBison

    Joined:
    Feb 1, 2014
    Posts:
    289
    Are you sure your suggested solutions play nice with ECS data formats? I haven't found a clean way to save entity prefabs, or any way to prep scenes in pure ECS data format without the subscene mechanisms provided in the ECS samples. I'd love to be proven wrong though, if you could point me at the documentation I've missed.

    Thanks!
     
  4. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    962
    Hey @tertle so would you say subscenes are currently only useful when you have chunks of a map with LODs in it just because of faster streaming? So basically the equivalent what Unity is doing in Megacity?

    Technically, subscenes are still a mystery to me in what they improve. At Reboot I asked about it and I got the impression that LocalToWorld matrices can be compressed more tightly but I don't know if that is just improving load times or actual render timing too.

    @CodeBison Depending on your workflow and if you have LODs I'd go with subscenes for a future-proof solution.
    When you're talking about big chunks loading in, that's exactly what subscenes are designed for. Under the hood subscenes create entityCache files that you can surely utilize for your automation.

    Which scenes you load from the main scene shouldn't be an issue when you have LODs. From the Megacity demo, everything is loaded but higher LODs only stream in when in vision/range. So, if you have a big open world map and your lowest LOD has the low-poly version of a big chunk you should be good.
     
  5. CodeBison

    CodeBison

    Joined:
    Feb 1, 2014
    Posts:
    289
    I was hoping for another way to get access to the entitycache creation functionality without having to create the actual subscene objects in scene. If I can't find a way to do that, I'll go the subscene route, but it's not my preference.

    Thanks!
     
  6. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    Not necessarily. That use is ideal for it but there's no reason you can't use it other ways. It's just a tool, using it is a choice.

    You can serialize entire worlds/scenes/prefabs/etc to file using SerializeUtilityHybrid.Serialize if you want. I had a quick discussion on it the other day here.

    https://forum.unity.com/threads/serializeutilityhybrid-serialize-deserialize.707405/

    I wrote a very nice system using this before scene conversion existed and it worked fine. It ended up behaving very similar to how scene conversion now works. I don't do this anymore because I'd rather use official tools, but you can totally do something like that.
     
  7. CodeBison

    CodeBison

    Joined:
    Feb 1, 2014
    Posts:
    289