Hey @Xarbrough_1 so just to confirm direct references (and just to confirm you mean you have a public GameObject field that you’re assigning to, correct? Not a public AssetReference field? or perhaps you mean the object is already part of the scene?) are not really supported when using Addressables. That is to say you can definitely use them in your project but they won’t have any affect on the reference counting happening behind the scene. As for your original post, I’d be curious to see what’s going on with those direct references. It may be we aren’t able to support that case given a potential scene dependency issue, or a bug in the Analyze logic, or a bug outright.
To your second post, given that direct objects in a scene have no weight as far as reference counts go, marking an object as DontDestroyOnLoad will lose all of its references when the scene that contained that object is unloaded.
Say you have SceneA with PrefabA. The asset bundle containing SceneA is loaded when you load SceneA and thus has a ref count of 1. This asset bundle contains all the data for your PrefabA. You move PrefabA to DontDestroyOnLoad (which basically just moves it to a new scene). Then you load SceneB (or unload SceneA in some way) so SceneA is unloaded, its ref count goes to 0 and the asset bundle is unloaded. The Object you have marked as DontDestroyOnLoad has not way to keep that bundle loaded so all of its data gets ripped out from beneath it.
Two possible solutions:
-
Call Addressables.ResourceManager.Acquire(…) and pass in the scene handle you get from loading SceneA. This will bump the ref count which will keep the bundle loaded even when you unload the scene. Do keep in mind that you’ll have to manually release that handle whenever, if ever, you’re done with that object that you marked DontDestroyOnLoad.
-
Make the object you would normally mark DontDestroyOnLoad an Addressable asset. Then have a script that loads it as part of SceneA and moves it to DontDestroyOnLoad. This will give that object its own reference count and will keep its data loaded until you destroy/release the instance yourself.
I hope some of that helps!