Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Need some clarification on asset referencing in Addressables compared to Resource.Load

Discussion in 'Addressables' started by JoeriCG, Feb 21, 2020.

  1. JoeriCG

    JoeriCG

    Joined:
    Apr 25, 2018
    Posts:
    17
    I often see Addressables described as the replacement for putting content in Resources, but there's two things I'm kind of missing here that I'm hoping some experts can chime in on:
    • Synchronous loading of Addressables is marked as deprecated, so there no intended replacement for Resources.Load, correct? Especially on larger projects that we're optimizing it can be a pain to change systems to load and instantiate stuff asynchronously.
    • From my understanding, assets (and the other assets they reference) in Resources are added to base build, and they reference the same instance of the asset as the game's asset database. Addressables don't do this, since if you build an asset bundles all its referenced assets are included with it (or reference to another asset bundle).
    What I mean by the latter point: say you have a Prefab A referencing Mesh 1 in your base assets folder and placed in a scene that's in the build list. Now there's a Prefab B in a /Resources/ folder that also references Mesh 1. If the game is build, and both Prefab A and Prefab B are instantiated in the scene, they reference the same Mesh 1 asset, correct?

    Now if you have a Prefab C that is marked addressable and uses Mesh 1. When you build the addressables, Prefab C is put in an asset bundle with its own copy of Mesh 1. When you instantiate Prefab A, B and C in a scene, the first two will reference the same asset but C will reference its own copy, meaning Mesh 1 is technically in memory twice.

    What I'm wondering is if the addressable system is supposed to work with this situation too somehow. Are addressables always intended to build to asset bundles or could they also be configured to work like the Resources folder and be included in the game build, sharing the same assets as in-build assets?
     
    ETGgames likes this.
  2. litebox

    litebox

    Joined:
    Aug 29, 2011
    Posts:
    158
    Absolutely, I'm refactoring one of projects to support Addressables and replacement Resources.Load() with
    Addressables.LoadAssetAsync() produces visual glitches when loaded object appears after small delay of 0.5sec and you see it. I didn't fix it yet but it looks like I need to pre-load every object to the Pool or something like this.
    Regarding second point what I understand is better to get rid of Resources folders at all, because in case of mixing Resources with Addressables they produce even more duplicates in resulting bundles.
     
  3. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    583
    Unfortunately, I don't think Addressables has any way to address a built-in asset. So if you have built-in assets and they are referenced in an addressable, you will always have at least 2 copies (if you have them both loaded). Hopefully they will add that functionality at some point, but I wouldn't hold my breath.

    Addressables are really more for seamlessly replacing AssetBundles, not so much Resources. Resources are just a bad idea to use in general, because it's horribly inefficient. Unity themselves recommended against using Resources long before Addressables was even a concept. I think including Resources as a migration source is more aimed to move people away from that system.

    Refactoring your game to make everything async is a pain, but from experience, I can say it's definitely worth it in the long run.