Search Unity

Obtain original GUID from assets in bundle?

Discussion in 'Asset Bundles' started by AFrisby, Apr 25, 2017.

  1. AFrisby

    AFrisby

    Joined:
    Apr 14, 2010
    Posts:
    223
    Is there a way in the new asset bundle system to obtain a unique ID which can be deterministically correlated with the original asset?

    Under the old system it was possible to use BuildPipeline.BuildAssetBundleExplicitAssetNames with CollectDependencies off (and manual calls to AssetDatabase.GetDependencies) to build a deterministic list of what's in a bundle and it's ID.

    Under the new system with dependencies forced on, I'm not sure this is possible anymore? Would it be possible to add a optional out parameter to LoadAsset(out string guid)/LoadAssets(out string[] guids) which outputs the original source UUIDs? (or something which we can use at bundle build time to output a correlating database)

    This may sound bizarre, but I do actually have a really good use case for this.

    Thanks!,

    Adam
     
  2. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    Hey @AFrisby
    In the 2017.1 release, we added a new parameter (addressableNames) to the AssetBundleBuild struct that lets you override the default addressable name (default: full qualified path) with one of your choosing. So you could construct AssetBundleBuild[] from AssetDatabase.GetAllAssetBundleNames & AssetDatabase.GetAssetPathsFromAssetBundle, then using the path returned from the second api, populate the addressableNames array using AssetDatabase.AssetPathToGUID.

    Doing this, you can then load an asset from an asset bundle using it's GUID as a string. I would also suggest using the BuildAssetBundleOptions to disable the additional loading maps as they basically become useless at this point and just contain duplicated data. (also new to 2017.1: DisableLoadAssetByFileName & DisableLoadAssetByFileNameWithExtension)