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

Defining new resources at runtime

Discussion in 'Addressables' started by andywatts, Jul 31, 2019.

  1. andywatts

    andywatts

    Joined:
    Sep 19, 2015
    Posts:
    110
    Anyone have tips on creating a new Catalog or IResourceLocation programatically at run time?

    I've a large number of assets on a server with naming conventions.
    I'd like to use Addressables for it's load, instantiate, cache, counter, and memory-management.

    Options I was thinking...
    1) Craft an IResourceLocator and add to existing ResourceLocationMap at runtime?

    2) Craft a catalog and use LoadContentCatalog.
    Catalog is just an asset- How to create them?
    Reverse engineer from Editor GUI or build scripts?

    Would either of these approaches be appropriate? TIA
     
  2. danilonishimura

    danilonishimura

    Joined:
    Jul 13, 2010
    Posts:
    70
    If you have a large number of assets, set them up in packs using addressables and selectively load the assets you need.
    Loading the catalog doesn't load the assets. Catalog is just a json file containing the asset keys and the path to the actual bundles, plus some base64 encoded stuff.

    Do you really need to create a catalog at runtime? The only case I can think of needing any kind of catalog creation, would be if you created bundles at runtime, which isn't possible as far as I know.
     
    unity_bill likes this.
  3. HugoClip

    HugoClip

    Joined:
    Feb 28, 2018
    Posts:
    52
    I would go with a ResourceLocator, you can either use a ResourceLocationMap or create your own.
    e.g. using an ResourceLocationMap

    Code (CSharp):
    1. public void AddResourceLocations()
    2. {
    3.   List<ResourceLocationData> locationData = new List<ResourceLocationData>();
    4.  
    5.   locationData.Add(new ResourceLocationData(new string[] {"key"},   "c:/path/to/asset_bundle.asset", typeof(AssetBundleProvider), typeof(AssetBundle)});
    6.  
    7.   var locMap = new ResourceLocationMap(locationData);
    8.   Addressables.ResourceLocators.Add(locMap);
    9. }
     
    unity_bill and andywatts like this.