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 Setting SceneSection in Post baking system - cause subscene not loading

Discussion in 'Entity Component System' started by eizenhorn, Dec 13, 2022.

  1. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    I'm in progress of migrating to Entities 1.0 and rewriting our runtime conversion to SubScenes. What we want is to have specific entities prefabs belongs to specific scene sections (and depends on level we want to load - pick specific scene sections prefabs to load post process for our mappings and caches and use. I don't want to manually add SceneSectionComponent to every prefab and decided to have PrefabsHolder for specific groups in subscene (with BakingOnlyEntity as we need them only for organized holding of entities before convert) where we set scene section index for prefabs in group we want to belongs to, they converts successfully, we have entities with buffers of entitity prefabs which we can acces in PostBakingSystemGroup, and system successfully processing them (iterating and setting every prefab entity SceneSection with specific section index because by default every prefab we get through GetEntity() belongs to 0 scene section which is absolutely not what we want). If we have code (below) in post bake system - subscene just won't load and throws regular error about missing scene header (well, expected as baking process broke).

    Is this another baking pipeline limitation? Which is in common, to be honest, very inconvenient, has restrictions because of this live conversion (which is just useless when you doing anything with CD and we personally never saw anything useful in that but opposite only annoyng things this live conversion introduces), extremelly basic, if you want to build anything real not just 1 cube sample - it will just interfere with you and instead of solving problems, it will create them :confused:

    Scene sections just useless here and we forced to split prefabs groups to sub scenes?

    upload_2022-12-13_16-13-40.png

    upload_2022-12-13_15-38-55.png

    upload_2022-12-13_15-40-16.png

    upload_2022-12-13_15-48-40.png
     
    charleshendry and bb8_1 like this.
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    bb8_1 likes this.
  3. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
  4. Jonas_DM_

    Jonas_DM_

    Joined:
    Feb 28, 2019
    Posts:
    22
    Hey eizenhorn,
    What you're trying to do is definitely supported, but I'm spotting 2 bugs in this baking code.
    1. You're not changing the scenesection of the 'PrefabHolder' entity. This breaks the rule with scene sections that you can only reference entities from section 0. (So entities in section 1 can reference entities in section 0, but not the other way around)
    2. In your PostBakingSystem you're setting the SceneSection SharedComponent but you're setting it to an invalid value since you forgot to assign the SceneGUID. The SceneGUID must match the guid from the baked scene.
    Inside the Baker you can use the GetSceneGUID method which you can use to assign a valid SceneSection to your prefab holder. (The entity should already have a SceneSection with a valid guid & section 0) Then in your BakingSystem you can use that valid SceneSection from the holder & also set the same SceneSection on your prefabs. Don't forget point 1 though, the holders can't reference entities/prefabs that are not in section 0.
     
    eizenhorn likes this.
  5. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    And I shouldn’t. As I said it’s BakingOnly entity and will be destroyed in the end of baking. It servers purpose only for structured editor representation. It references prefabs entities when they all in 0 section before post baking and that completely valid. Because in the end of baking process holder wouldn’t exist and wouldn’t reference anything.

    Ah yeah that's was the issue here, completely forgot about SceneGUID, thanks for pointing to my blindness :D, initially it was in Baker for prefab itself where I've set scene GUID
    upload_2022-12-18_12-51-39.png
    and when I've moved form setting that on every prefab to intermediate baking only prefab holder with post baking system, responsible to change section from one place configuration, I completely forgot to transfer SceneGUID.
     
    IsaacsUnity likes this.