Search Unity

Asset Bundles - names and hashes

Discussion in 'Asset Bundles' started by KBaxtrom-LevelEx, Jun 14, 2018.

  1. KBaxtrom-LevelEx

    KBaxtrom-LevelEx

    Joined:
    Feb 5, 2018
    Posts:
    28
    We are digging into an issue when updating iOS/Android apps that are using asset bundles downloaded from a url. We are trying to sort out what can be going wrong. In particular, one of our Materials is referencing a texture in a prefab. When we load the scene prefab the MainTexture of the material is Null. We have all asset bundles build stored in a remote location and only pull down asset bundles which have new hash values. The issue goes away if we completely uninstall the previous app version (to force a fresh pulldown of the asset bundles) or force all new asset bundles to have a new hash value. So the issue appears to be with our asset bundle system. We detect all dependencies from a scene based on the manifest file and download asset bundles using WWW.LoadFromCacheOrDownload(url, hash, 0); If this is working as expected it should only pull down new assets if the name or hash has changed.
    • It's unclear what goes into the hash value for each asset bundle. Is more information on what generates this value? For instance, if we delete the library folder and regenerate the build we get asset bundles with different hashes. When using the deterministic hashes option I would expect these to be the same between builds if no content has changed
    • If an asset bundle changes name between builds, but the hash value doesn't change would that cause an issue? See example below
    In Build 1
    an asset bundle 'Prefab_36' is depended on asset bundle 'texture_342' with hash a49a8f02b455408eb3121ec8dcc96e66 which contains a texture called TestTexture.png

    In Build 2
    an asset bundle 'Prefab_36' is depended on asset bundle 'texture_336' with hash a49a8f02b455408eb3121ec8dcc96e66 which contains a texture called TestTexture.png

    We are using the asset bundle graph to generate our asset bundles. Teach texture_## includes a single texture. In this case the texture the material is referencing is in texture_342 and texture_336 in each respective build.

    As I said as a fresh install there is no issue, but when we try to incrementally pull down the new changes we get a null texture.
     
    Last edited: Jun 14, 2018
  2. KBaxtrom-LevelEx

    KBaxtrom-LevelEx

    Joined:
    Feb 5, 2018
    Posts:
    28
    Little more information that we've gathered.

    We have a scene asset bundle which is depended on several asset bundles. In particular, it is depended on 'Prefab_36 in the example above. The build is correctly downloading the tree of dependencies in build 1 and build 2. However, the scene bundle appears to have a lot of binary differences, but the hash has not changed so a new one isn't downloaded. We're still trying to understand what controls this hash value. If we forcibly delete this scene bundle it will redownload the new one and the issue resolves itself.
     
  3. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    So there's quite a bit of data that goes into the hash value, and several low level systems are involved in this process. The first key system is the Asset Database as it imports source assets and generates a dependency hash. This dependency hash is mainly used to know when the asset has changed and needs to be reimported. The second key system is the Build Pipeline as it collects the dependency hashes for all the assets and their dependencies being put into a specific bundle, grabs other key pieces of information from other areas, and then hashes that data to produce the final hash value you see.

    If you are deleting the library folder, rebuilding using the same content, and seeing different hashes, this tells me that the problem most likely is with one or more asset dependency hashes. This can be due to custom importers that are being used that are not deterministic, or even a problem in the asset database not detecting that an asset has changed properly before the build is triggered.

    There is quite a bit of work being done behind the scenes to improve both of these systems. First, we have the Scriptable Build Pipeline package that will be discoverable in Unity 2018.2's Package Manager. In this new package we have implemented the Asset Bundle Build Pipeline using public C# code as much as possible as well as fixed many build issues that the existing pipeline has today that would require major rework or rewrites to fix (including this hash value). In addition the Asset Database is under a large rework (no eta) that makes it more performant on larger projects as well as better track and reimport assets and their dependencies.

    Yes, the runtime asset bundle cache system uses Name & Hash pair to uniquely identify each asset bundle on disk. So if you rename a bundle, it is considered a new bundle when requested even if the hash is one you used previously.