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
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.
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.
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.
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:
Scene has MeshRenderer referencing a Material, which itself is an AssetBundle (other group).
GameObject of this MeshRenderer is flagged with DontDestoryOnLoad
New scene is loaded in single mode.
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 -.-).
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:
prefab containing meshRenderer and material.
Steps:
open scene (non addressable)
use Addressables to instantiate prefab as GameObject into scene.
mark instantiated addressable GameObject as DontDestroyOnLoad
load some new non-addressable scene.
That right? understanding exactly what your code is doing, and which things are addressable will help.
This problem was happening last week with 1.1.4. Basically the steps to reproduce were:
Inside an addressable scene, load an adressable prefab that has DontDestroyOnLoad with some addressables of its own that it loads.
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.
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:
SceneA uses addressables to load SceneB
SceneB uses addressables to load PrefabX
key detail: if I understand correctly, at this point PrefabX does not have a direct reference to MaterialY
PrefabX is marked as DontDestroyOnLoad
PrefabX uses addressables to load MaterialY
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.
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.