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

Question How to guarantee subscenes have been converted before play mode?

Discussion in 'Entity Component System' started by PublicEnumE, Apr 19, 2021.

  1. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    My project contains several subscenes. When they are converted, I’d like to collect some information from each one, and write it into a single json file. The resulting file would contain combined data from all of my subscenes.

    But in order for this to work, all of the subscenes would need to be have gone through the conversion process before play mode is entered. Otherwise, that json file could be missing data from some of the subscenes.

    Is there a way to guarantee or force this to happen before the editor enters play mode?

    Also, are subscenes guaranteed to have gone through conversion before a build is made?
     
  2. Rupture13

    Rupture13

    Joined:
    Apr 12, 2016
    Posts:
    129
    A converted subscene is just a serialised asset. So, assuming your subscene is closed when you enter play mode, there exists a converted subscene. However, the converted subscene may not be up-to-date with all your changes (for example changes to authoring code). To guarantee it's up-to-date, you would reimport the subscene.

    This means that checking whether a subscene is converted seems pointless, as it could still be outdated even if converted to entityscene. I don't think you can really check whether the converted subscene is in accordance with all changes you may have made, so I think the only way to guarantee up-to-date converted subscenes would be to reimport all your subscenes with the "Reimport all" button you see when selecting multiple subscenes in the hierarchy (while having all the subscenes closed).
     
    PublicEnumE likes this.
  3. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    Aw, that’s a bummer. But this is all still experimental - maybe there will be more code support for controlling Subscenes in the future. :)

    The testing I’ve done (simple breakpoints in my Conversion code) shows that sometime subscenes aren’t updated with your latest changes until you actually hit the play mode button.

    That’s true even if it’s been hours since you made those changes. That confused me, since Unity explained in a Unite talk that closing a Subscene puts it in a queue, to be converted in a background thread shortly thereafter.

    Maybe that logic had changed since they have that talk. But it’s unclear, and it would be great to get clarification.

    Thank you for the advice.
     
    Last edited: Apr 19, 2021
    Rupture13 likes this.
  4. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    954
    I have a gameobject in the subscene that has something like GhostScene_Loaded component.
    After this is converted and loaded it can be picked up by a system, then you know everything's loaded.

    I only use this for runtime but this can also be used in the editor. If you look at the entities in DOTS editor you can see all the loaded entities from the subscene. Quite interesting in how it reacts when the subscene is open/closed or loaded/unloaded.
    Anyway, an editor script using EntityManager will be able to read this data even when the game isn't running.