Search Unity

Request: asset instance to asset name lookup

Discussion in 'Asset Bundles' started by Deleted User, Feb 1, 2021.

  1. Deleted User

    Deleted User

    Guest

    Hi!

    I would like to request the following method to be implemented:

    Code (CSharp):
    1. public string AssetBundle.GetLoadedAssetName(UnityEngine.Object asset);
    Which would return the path/address of the given asset inside the bundle, or null/empty if the asset was not loaded from the bundle in question. (In more abstract terms, this would be the inverse function of the LoadAsset methods)

    Unity must keep this information somewhere internally, because if you call AssetBundle.LoadAsset(string name) and the asset has already been loaded, the loaded asset will be returned instead of a new one. So there must already exist a map (string name -> Object asset), and all I'm asking for is that this is exposed publicly.

    This would make it possible to keep track of the identity of assets loaded from bundles. Currently, if an asset was loaded using AssetBundle.LoadAllAssets(), there is no way to know how to load that specific asset again, since we have no means to find out the name used to load it. This forces us developers to come up with less ideal solutions like putting custom manifests inside our bundles or storing the name used to load the asset on the asset itself.