Search Unity

Addressables General Questions

Discussion in 'Addressables' started by leobilck, Sep 12, 2019.

  1. leobilck

    leobilck

    Joined:
    Nov 13, 2014
    Posts:
    12
    I have compiled a few questions regarding Addressables and how to properly handle some edge cases:

    1. What is the best way to override how Unity downloads bundle files?
      • Is it by overriding a class/interface? Should I replace the default object somewhere? Etc.
    2. Is it possible to add authentication/token parameters to the URLs when downloading bundles?
    3. What about using multiple endpoints with content replication?
    4. What files must be commited on the version control system and which ones can be safely ignored?
      • Must I commit Assets/StreamingAssets/aa/* auto-generated directories and files?
    5. Are addressables bundles' hashes deterministic? Even if I don't share any library folder across different machines?
      • We are planning on building our addressables bundles without including hashes on the file names. So for content updates (and same arbitraty bundle version) we could just replace the uploaded bundles.
    6. It's currently not clear how caching works for the Addressables system. If I build new bundles and most of the bundles don't change (same hash), will the runtime player detect this and keep the cached version?
    7. Are cached bundles deleted from cache automatically when the user downloads a new version?
    8. How to properly check if an Addressable is cached? I have found this topic, but will "Addressables.GetDownloadSize" work if the user is offline? What if I want to delete cached files, how should I do that?
    9. Assuming that the platform is the same, are Addressables' bundles compatible across different Unity versions? "How" compatible?
     
    Last edited: Sep 12, 2019
    anisimovdev, FlightOfOne and xLeo like this.
  2. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    The default AssetBundleProvider.cs is not designed for overriding. So you have to copy, rename it, then start hacking.

    Yes, by *overriding* AssetBundleProvider.cs. The signed url feature will be eventually added to the system, but you're welcome to share your code snippets.

    How about delegate that to a CDN?

    Depends on your setup,
    • Commit: AddressableAssetsData/*
    • Delete: Assets/StreamingAssets/aa/*, those are copied by build pre-processing script, and should be deleted by post-processing script. So you can just clean it up.
    • Sync to server: REMOTE_BUILD_PATH (remote catalog, remote bundles)
    • Depends, Library/com.unity.addressables/* (setting file, local catalog, local bundles) commit or sync to other devs, only if you like other devs to load the built contents (catalog, local/remote bundles). Usually happens in bigger team to have dedicated dev/CI to build assets and sharing across team.
     
    FlightOfOne likes this.
  3. leobilck

    leobilck

    Joined:
    Nov 13, 2014
    Posts:
    12
    Yeah, we are using a CDN for distribution. The point about that question was to actually being able to change the CDN endpoint through remote settings and territories, using the same build.

    Thanks for your answers, they were really helpful. :)

    Any ideas regarding the runtime content updates/caching-related questions?
     
  4. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    ClearCache
    *Should be* yes for the same machine, see more in
    https://forum.unity.com/threads/deterministic-asset-bundle-building.703826/
    https://forum.unity.com/threads/randomized-non-reproducible-hashes-in-asset-bundle-names.731771/

    I would say no hash probably a bad idea, if assets served under a mis-configured http server, or a CDN. Adding hash is the same simple way to avoid all the weird thing about caching. Of course if it's deterministic.

    The system using built-in caching system, in your case, crc check will prevent you from downloading the unchanged bundles.

    Not yet, and no ETA. You can rely on the default behavior of caching. Which is unlimited size (bad) and expires in 150 days. Search documentation for CacheInitializationSettings for overriding.

    Yes, if the app already fetched the latest catalog then goes offline. It used to be a bug, but I assume it's fixed in latest version.
    No, if the app goes offline since launch, which never has a chance to fetch the latest catalog.

    Check the Caching.ClearCache API. However finer control requires the bundle name, which you need parse yourself from loaded catalog. In another world, not API for delete all cached bundles for given addressable/label, but you probably can build it on your own.

    Honest speaking, I don't know. As I remember a folk said some bundle works, some don't. Addressables are just preparing asset bundle for you at the moment (until at some point it rolls out a new format, in a very long future), so all the assets bundle limitations applied. You may post/search on the asset bundle sub-forum for help.

    If have solved your specific issue mentioned in the thread, feel free to give an update!
     
    JoRangers likes this.
  5. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    Didn't realize that. But seems custom domain binding can solve the issue of changing CDN endpoint, and a good CDN shall taking care of territories for you on the fly? In case it's not, a flexible workaround is to customize your RemoteLoadPath using dynamic {} notation. Or if you really want more control, hacking the provider file.
     
  6. leobilck

    leobilck

    Joined:
    Nov 13, 2014
    Posts:
    12
    So. We have been working in a "customizable" way to load bundles according to their address prefix.
    Got it working based on the default AssetBundleProvider and have attached the current files on this post.

    I have issues though when trying to work with Firebase Storage, I guess it's because the catalog is also on an online bucket (and is loaded through Firebase Storage authenticated request). What is the easiest/fastest way to load the catalog? Do I also need override a catalog provider?

    So, besides that I got a couple extra questions/feedbacks:
    • I had issues when I tried to use Assembly Definition Files on these classes. Is there an issue with the addressables system to load/show providers that are not in the default Assets' dll?
    • Do we need to add "AddressableAssetsData/*/addressables_content_state.bin" to the repository and/or don't commit every change? What would happen if we don't add these files to the repository?
    • We have a bunch of scenes on our Addressables Asset Settings (a.k.a. "Groups") and the Bundle Mode is set as "Pack Separately". Every time we click on "Build Player Content", it seems that all bundles are being built, regardless if they changed or not. What are we doing wrong? Is that the expected behaviour?
      • What should we do to build only the updated/changed content? It's ok to have the need to perform a full-build on a developer machine at least once.
    • How can we create Editor-compatible bundles? It that a possible thing to do without changing platforms?
    • What is the easiest way to get the Caching API handle/id of a specific AssetReference?

    Thanks!
     

    Attached Files:

  7. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    You can get a signed catalog url first, then load the catalog manually with LoadContentCatalogAsync.

    I don't think you can load dynamic code this way. You may search the subforum for reference.

    Probably no. The bin file is a *snapshot* of an asset database. Lately used for preparing a content update. Pls see the official document for details.

    Pls search build cache / build part in the subforum.

    Do you mean build asset bundle once for all platforms? I don't think so then. You have to change platforms for each build.

    I don't get it. Get cached asset bundle for specific asset reference?
     
  8. robinryf

    robinryf

    Joined:
    May 22, 2014
    Posts:
    54
    Favo-Yang likes this.
  9. leobilck

    leobilck

    Joined:
    Nov 13, 2014
    Posts:
    12
    Coming back to this topic, I have successfully implemented a Firebase Storage integration based on @robinryf implementation.
    That implementation wasn't working properly because default AssetBundleProvider was overriding the customized one and for other reasons (that I don't remember exactly why right now :().

    I'll attach a few files here related to that implementation. Most of them won't compile due to some minor dependencies, I guess it's easy to figure out what to do to make it work.

    I have a few other comments/questions about the Addressables system that are bugging us:
    • [FEEDBACK] We have implemented a dynamic server endpoint, which is particularly useful to alternate between Editor-hosted server and production server without rebuilding all the bundles (and catalog). As a suggestion, I believe that having a default server endpoint and being able to change it in runtime should be the default option for Adressables;
    • [FEEDBACK] We managed to create a customized AssetBundleProvider on a separate assembly. It seems to be working ok.
    • [FEEDBACK] Using "Player Version" override option caused a lot of issues for us, since the providers are set on the catalog and (probably) the catalog is also cached. We changed the default provider for a customized one, rebuilt the addressables but nothing happened, it took us a while to notice why that weird behaviour was happening;
    • [BUG] During "Packed Play Mode" (and probably in a standalone runtime), the operation "Addressables.LoadSceneAsync" is not marked as "Done" when an exception is raised. To easily reproduce that, just use Editor-hosting and don't start the service. The "AsyncOperationHandle<SceneInstance>" will completely ignore what happened.
      • As a side note we have implemented an (ugly) workaround for that, but i has its issues.
    • IMPORTANT: How can we get the remote path for a specific AssetReference? We have tried using "Addressables.LoadResourceLocationsAsync", but it only returns 1 IResourceLocation and its InternalId corresponds to its local project path (check image below). If we could get the proper remote path we could then be able to handle caching in a more customized way. How does that location data get transformed into a remote path location (used by the AssetBundleProvider)?
      • upload_2019-10-23_16-52-7.png
    • [FEEDBACK] There should be a way to check if any version of a AssetReference is already cached. I know that it's possible to use ComputeSize, but there's a difference between those two. Sometimes it may be optional to the user to update the game's content.
     

    Attached Files:

    Favo-Yang and KB73 like this.
  10. xLeo

    xLeo

    Joined:
    Sep 21, 2010
    Posts:
    194
    For anyone that found this topic: turns out that all IResourceLocation objects can have as many dependencies as needed and the base AssetReference (including scenes) is not the actual bundle representation, it's just an aggregator of its dependencies. In my case it was just 2 dependencies: builtin-shaders (local bundle) and the scene remote-hosted bundle. @Favo-Yang is that right?

    So, based on these finding you can have a finer Caching control by using the IResourceLocation (obtainable from method "Addressables.LoadResourceLocationsAsync(AssetReference)") and iterating over its dependencies.

    I have attached an utility static class to this post which might be useful to get some Addressables general references.

    Now that i know about it, all this seem pretty basic, convoluted but basic. A good documentation would have solved most (if not all) of my problems.

    [Off-Topic] Apparently I have been posting with different accounts (personal and company account). "leobilck" and me are the same person.
     

    Attached Files:

  11. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    Yes. the IResourceLocation just an asset key, the ComputeSize, DownloadDependencies, and LoadAssetAsync... will all take care of the dependencies when handle a location.
     
  12. leobilck

    leobilck

    Joined:
    Nov 13, 2014
    Posts:
    12
    @Favo-Yang Is it possible to evaluate and access addressables' Profile Entries in runtime? How?
     
  13. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    You mean switch addressable's profile at runtime? I don't think it's possible. As the profile is built into settings.json and perhaps catalog.json.

    The close thing is to build and load additional catalog, depends on your intention.
     
  14. xLeo

    xLeo

    Joined:
    Sep 21, 2010
    Posts:
    194
    No, I mean just getting the current Profile Entries values in Runtime:
    upload_2019-10-25_3-41-59.png
     
  15. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    I see, I'm not sure for the customized fields like ServerUrl, EditorServerUrl in your case. But the default ones are "rendered" into settings.json under /Library/com.unity.addressables/*/.

    Like the marked line is actually the LocalLoadPath
    upload_2019-10-25_15-5-36.png

    That's what the library does in general - it don't take whatever we see in the panel and stores to runtime. instead it converts those into various files and places.
     
  16. leobilck

    leobilck

    Joined:
    Nov 13, 2014
    Posts:
    12
    Yes, I knew about that.
    I was just wondering if it was possible to get "EditorServerUrl" to remove the need to update it on different machines before building the application.
    Sometimes (ok, a lot of times) we forget to set it before triggering the build on different developer's machines.

    Different question now: why do bundles get rebuilt when their dependency tree don't change? Every time we perform an addressables' build, everything is rebuilt from scratch (or at least takes the same time to build). Shouldn't only the catalog and the changed bundles get rebuilt?
     
  17. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    Not an expert for the build performance, you may search the forum for more informations, as I remembered the build can leverage unity cache server, but I'm not entirely sure.
     
  18. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    392
    Is this still the case?
    This seems idiotic, if old bundles don't get removed you're gonna end up with a folder with several GB of useless files after X updates.
    Why would they not simply overwrite/delete the bundles?

    Also after 150 days the bundles get removed and you have to redownload all your bundles again for no reason?
     
    Last edited: Sep 13, 2020
    wavs likes this.
  19. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    392
    Bump
     
    xLeo likes this.
  20. FIFTYTWO

    FIFTYTWO

    Joined:
    Oct 21, 2014
    Posts:
    49
    Is it possible to tweak Addressable Analyze tool to exclude *.cs from duplicate search? I have some not addressable parts which share code with addressable assets and I think script sharing is not a big duplication issue but they spam result window and it is hard to look through them to find real issues.