Search Unity

Scene loading problems

Discussion in 'Addressables' started by WeltenbauerRenn, Jun 21, 2019.

  1. WeltenbauerRenn

    WeltenbauerRenn

    Joined:
    Jun 20, 2017
    Posts:
    40
    Hello everyone,

    I'm trying to setup Addressables for our project which is in the early blockout phase. I got a lot of problems with missing references to assets (like Materials and TerrainSettings) and some strange errors when packing groups together or separated.

    The loading process looks like this:
    Loading_Scene -> Manager_Scene -> Blockout_Scene1 <-> Blockout_Scene2
    Only the loading scene is added as build in scene and the rest is loaded via Addressables. What I noticed:

    1.) Flagging GameObjects with DontDestroyOnLoad doesn't prevent referenced assets from unloading when the scene gets unloaded (like LoadSceneMode.Single).

    2.) None of the blockout scenes can be loaded when the Group is set to "Pack Separately". Getting this error
    upload_2019-6-21_16-30-46.png

    3.) When the scenes are packed together I can load both scenes. But the Terrain in one blockout scene loses the reference to it's TerrainSetting but the other works fine. Every terrain has it's own setting and the two are in a different group (packed separately).

    I'm testing mostly in the Editor in Packed Mode and do a clean all and rebuild for every iteration.

    Is there a special way of using scenes with Addressables? We are planning of using small scenes for world streaming.

    Thanks for any help :)
     
    magmagma likes this.
  2. WeltenbauerRenn

    WeltenbauerRenn

    Joined:
    Jun 20, 2017
    Posts:
    40
    Update about 3: I got it working by removing the texture and terrain setting from AGroup. Can't scenes use other addressables?
     
    magmagma likes this.
  3. magmagma

    magmagma

    Joined:
    Oct 27, 2017
    Posts:
    41
    I have seen this problem about objects with DontDestroyOnLoad getting all the references loaded via addressables destroyed. It's kind of annoying. It doesn't happen if you do this from a scene that is not an addressable though apparently.
     
  4. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    they should be able to, but we've come across this bug elsewhere as well. we are looking into it.

    This was completely broken up until around addressables 0.7.x. So if you are using the latest, then DontDestroyOnLoad should be working fine (assuming it's not tied to the first problem). If there's an issue with DontDestroyOnLoad please let us know.
     
  5. WeltenbauerRenn

    WeltenbauerRenn

    Joined:
    Jun 20, 2017
    Posts:
    40
    Hello Bill,

    some problems with the terrain are related to shader stripping. Terrain shader behaves very strange when building in batch mode, maybe this is also related HDRP. I turned off variant stripping and is seems to work. Maybe in the future I need to include a reference scene in the build that is just there to prevent stripping.

    About DontDestoryOnLoad:
    As far as I understood, GameObjects that are flagged with DontDestoryOnLoad gets into a different scene and also don't count as alive for the origin scene (or the scene is the only reference point for dependencies). What I had:
    1) Scene has MeshRenderer referencing a Material, which itself is an AssetBundle (other group).
    2) GameObject of this MeshRenderer is flagged with DontDestoryOnLoad
    3) New scene is loaded in single mode.
    4) Old scene gets unloaded und reducing refcount to Material -> Material gets unloaded -> Mesh is pink.

    Simple workaround is to just use load additive and take a bit more care about scene management (old code still in used -.-).
     
  6. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    I'm not sure yet if this is a bug or an issue of addressables being unaware of what's happening outside it. To help clarify, which things are addressable in this scenario, and what exactly are your steps. It sounds like it might be:

    Addressable:
    1. prefab containing meshRenderer and material.
    Steps:
    1. open scene (non addressable)
    2. use Addressables to instantiate prefab as GameObject into scene.
    3. mark instantiated addressable GameObject as DontDestroyOnLoad
    4. load some new non-addressable scene.

    That right? understanding exactly what your code is doing, and which things are addressable will help.
     
  7. magmagma

    magmagma

    Joined:
    Oct 27, 2017
    Posts:
    41


    This problem was happening last week with 1.1.4. Basically the steps to reproduce were:

    1. Inside an addressable scene, load an adressable prefab that has DontDestroyOnLoad with some addressables of its own that it loads.

    2. Load a new scene. Now the object will remain on DontDestoyOnLoad but its references to addressables are now null.

    I did see that in the changelog of 1.1.5 it says "Fixed scenario where scene unload destroys instantiated objects in different scenes." so that might have been fixed now.
     
  8. WeltenbauerRenn

    WeltenbauerRenn

    Joined:
    Jun 20, 2017
    Posts:
    40
    The "problem" is still there.

    Ok I did a quick test (editor, packed mode):
    - Have 3 scenes (A,B,C). B and C are in Addressables. A loads B, B loads C. All in Single mode.
    - B has a GameObject referencing a Material which is in Addressables. That GameObject gets marked as DontDestroyOnLoad

    When C is loaded, the GameObject lost the connection to the Material. All done in 2019.1.10f1, Addressables 1.1.5
     
  9. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    I'm not sure exactly what's unloading the material. I think I may need a repro project to track this down, but let me rephrase things to make sure I understand the situation...

    So, let's say your prefab is "prefabX" and your material is "materialY".

    None of these things have direct references to each other (None of the scenes have the prefab or material directly in them, and PrefabX does not have a direct reference to MaterialY)

    So your steps are:
    1. SceneA uses addressables to load SceneB
    2. SceneB uses addressables to load PrefabX
      1. key detail: if I understand correctly, at this point PrefabX does not have a direct reference to MaterialY
    3. PrefabX is marked as DontDestroyOnLoad
    4. PrefabX uses addressables to load MaterialY
    5. SceneB uses addressables to load SceneC
    Is this right? It would seem that for some reason, MaterialY is getting unloaded. It could be due to addressables unloading it, or it could be the engine (loading a scene calls UnloadUnusedAssets under the hood). Either way, I'm confused as to why either we would think to release it, or the engine would be unaware that it was still being referenced.
     
  10. magmagma

    magmagma

    Joined:
    Oct 27, 2017
    Posts:
    41
    I confirmed it still happens too. In an addressable scene loading an object with addressable references (and the object has DontDestroyOnLoad), and then change the scene, the object will persist (as it should) but all the addressables it has internally will have been unloaded.
     
  11. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    So the steps I said are your exact situation? And are you and @WeltenbauerRenn working together? Or two people that happen to have seen a similar bug?

    I just tried to repro it based on the steps above, and I'm not seeing this problem. Can you create a Unity bug with a repro project?
     
  12. magmagma

    magmagma

    Joined:
    Oct 27, 2017
    Posts:
    41
    We are not working together, we came upon the same bug it seems.

    I tried to make a minimal reproduction project and it didn't occurr... It seems something else is required for the bug to happen.
     
    Last edited: Aug 19, 2019
  13. WeltenbauerRenn

    WeltenbauerRenn

    Joined:
    Jun 20, 2017
    Posts:
    40
    Last edited: Aug 20, 2019
  14. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    great, thanks!
     
  15. melissae

    melissae

    Unity Technologies

    Joined:
    Dec 5, 2018
    Posts:
    9
    Defect has been closed as fixed.
     
    magmagma likes this.