Correctly use AssetReference and direct reference

So I’m fairly new to Addressables/AssetBundles as a whole, reading thought the documents I did learn a thing or 2. And about the “Replace ‘direct reference’ with AssetReference”, I have one question is that, assuming like this:

  • I have an Addressables scene
  • In that scene I have a GameObject with an AssetReference field
  • That field type is a class derived from ScriptableObject
  • That class have fields that use reference (prefabs, scriptable object, audio clip,…)

So does these reference need to be AssetReference too to avoid duplicate? or only those that on the scene need to be AssetReference

1 Like

Man don’t colour your text like that; makes it really hard to read.

But to answer your question, it depends. One tenant of addressables is to only load assets into memory when you need it. So, in your situation, do you need those assets all the time/right away? If you may only sometimes need those assets, then make them addressable references. If they’re needed all the time, then direct references are fine.

In either case, you do want the assets to be in your various addressable groups to prevent the assets being duplicated come build time.

1 Like

So to be specific:

  • I have a SO scripts called AudioCueSO which contain a list of AudioClip and all other related data
  • If I use ‘direct reference’ for those fields, will it create duplicate?

I mean does ‘direct ref’ vs AssetRef related to duplication? Cause I did get some duplicate when using the same asset for normal scene, addressable scene

PS: Sorry if this are some what basic stuff, I spend a lot of time reading though the docs before asking this

If the assets you are direct referencing in the addressable scriptable object themselves aren’t in addressables groups, they will be duplicated at build time if they are referenced by other Objects.

Hence why I mentioned putting those referenced assets in addressables groups too. Not because you might want to point to them with addressable asset references, but so that they’re built into the assets used by the addressables system to avoid duplicated assets.

You can see where this is occuring by using the Window → Asset Management → Addressables → Analyze window.

1 Like