Search Unity

Question Not quite understanding the point of Addressables

Discussion in 'Addressables' started by RogueStargun, Jun 7, 2023.

  1. RogueStargun

    RogueStargun

    Joined:
    Aug 5, 2018
    Posts:
    296
    I will admit, after working on my project for 3 years, I still don't get the point of addressables nor do I understand the consequences of marking an asset as addressable.

    Over the course of 3 years, I marked certain things as addressable, and other things as not addressable. Now I have no idea what the memory consequences of doing this are.

    I have an audiocue system (where every audiocue is a scriptable object) that seems to have audiocues fail to fire if a given audiocue is not marked as addressable?

    If I mark, say a mesh as "addressable" but don't load it using the addressable system, what are the consequences exactly?
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,935
    Have you ever even opened the addressables groups window (or read the documentation for that matter)? That's the point of marking something addressable, so it gets built into your addressables group's content bundles. From there you can organise its place amongst your various groups.

    The point of addressables is to organise certain assets into logical groups, either so they can be loaded into memory on demand, or distributed for content delivery reasons. Generally if you plan to use addressables, everything in your project should be built into addressables groups, with just a bootstrap scene to kick things off.

    Probably good to do some reading: https://docs.unity3d.com/Packages/c...editor/AddressableAssetsDevelopmentCycle.html
     
  3. RogueStargun

    RogueStargun

    Joined:
    Aug 5, 2018
    Posts:
    296
    That documentation is not very helpful. The thing is, I'm not entirely sure how Unity manages memory without addressables nor does the documentation make it clear what happens when you start using addressables? Its all very opaque, and there's not clear statement of the problem which addressables is solving.

    The way I think it works (after consulting a certain AI chatbot which may be unreliable), is that grouping addressables does some sort of reference counting under the hood such that an entire addressable group is unloaded from memory only if all references to all items in the group disappear.

    Presumably without addressables, the scene itself is the unit of reference counting. Is this a correct statement?

    So if I take all the audiocues scriptable objects in my game, and mark them as addressable, will audiocues persist in memory until I land on a scene with 0 audiocue references? Will all audiocues simply additively load forever until I shut down the game? What exactly is going on under the hood?
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,935
    Sorry but the docs are super clear and you need to take the time to read them, alongside following tutorials on the basics of how to use addressables.

    For example, there's a whole page on memory management and how it works with addressables: https://docs.unity3d.com/Packages/com.unity.addressables@1.21/manual/runtime/MemoryManagement.html

    And you have diagnostics tools such as the event viewer to keep track of reference counts. So there's zero reason to be guessing how it works.

    There's a lot more to addressables than just 'marking assets addressables'. If that's literally all you're doing then you might as well not use it at all, because you've only understood about 1% of the system.
     
  5. RogueStargun

    RogueStargun

    Joined:
    Aug 5, 2018
    Posts:
    296
    Ok that document was indeed what I was looking for. It looks like Addressables does use reference counting semantics, and I have been misusing it to a certain extent.

    Since I use scriptable objects in my game rather extensively which persist across scenes, I've taken the blunt approach of marking all such objects a addressable. I now realize that I've encountered issues with scriptable object duplication since I'm doing this marking rather inconsistently.

    Thanks for pointing out the docs!
     
  6. RogueStargun

    RogueStargun

    Joined:
    Aug 5, 2018
    Posts:
    296
    After 2 years of working on my project, I finally realize that virtually all my gameobject references on my scriptable objects actually break at random when I started marking things addressable. I'm now going to have to spend at least 8 hours migrating my GameObject refs to AddressableAsset refs :(
     
  7. RogueStargun

    RogueStargun

    Joined:
    Aug 5, 2018
    Posts:
    296
    Alright, I spent a good 2 hours on it, and I suddenly realize that the smarter move is to simply unmark most if not all of my gameobject an non-persistent scriptable objects as non-addressable except for certain persistent scriptable objects used to transmit information across scenes.

    It took me a while to understand that Addressables are simply boxed and ref counted in memory, but that this also breaks asset references like crazy for things improperly flagged as addressable.

    I built my game following a lot of design principles from the Chop-Chop project for using persistent scriptable object event managers, but I didn't understand that scenes manage scriptable object memory with ref-counting, so boxing scriptable objects in memory.

    I think I understand how I could use Addressables to build DLC, but using them promiscuously across the entire project (or any project) is likely overkill.
     
  8. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    addressable are useful in very limited cases: loading stuff from a server

    that's it

    when i want to control memory usage I use an intermediate: a scriptable object look up table between prefabs (fat in memory) and other scriptable objects fingerprint (tiny memory)

    i reference the fingerprint in my instancing stuff, it does a lookup and retrieves the prefab as needed, which pulls all assets in memory

    unity automatically unloads oldest objects

    that's about 10x less boilerplate code that adressables and is predictable