Search Unity

How are AssetFileHashes calculated?

Discussion in 'Asset Bundles' started by adamt, Aug 17, 2017.

  1. adamt

    adamt

    Joined:
    Apr 1, 2014
    Posts:
    116
    I'm building AssetBundles into my iOS and Android binaries utilizing the StreamingAssets workflow. When I do this, I use a Jenkins build on one of my build servers. The server is either a Mac for iOS, or a PC for Android.

    Unfortunately, even with zero changes to our assets, the AssetFileHash seems to be different if we build our AssetBundles on our PC build server vs our Mac build server. This is causing issues where our game thinks new assets have been uploaded, and re-downloads them even though nothing has actually changed. In the short term, I can ensure our iOS assets are getting built on the Mac server and our Android assets are getting built on the PC server, but it's concerning to me to not know how Unity calculates this hash.

    Is there a way I can reliably calculate the hash myself (e.g., doing an MD5 of the directory and its contents) to see if it's different between OSes or if something else is going on?

    Edit: I just switched the AssetBundle build to our Mac build server and the AssetFileHash of the generated manifests match up with the previous iOS player build, so it does seem as though the hash calculation is somehow different between Mac and PC versions of Unity. We're using 2017.1.0p2, for reference.
     
    Last edited: Aug 17, 2017
  2. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    So if it's different on mac vs pc, that typically means your version control software is normalizing line endings to match the target platform (Win: CRLF, Mac: LF). The line endings do end up as an input to the hash in the current AssetDatabase. As a note, Unity writes all data using LF regardless of platform.

    If you use Git (first option preferred):
    git config --global core.autocrlf false
    git config --global core.autocrlf input

    If you use Perforce (use unix or shared workspace options):
    http://answers.perforce.com/articles/KB/3096
     
    dimmduh1 likes this.
  3. adamt

    adamt

    Joined:
    Apr 1, 2014
    Posts:
    116
    You know it's funny, about an hour after I posted this question, the thought of different file endings came up in my head but I dismissed it.

    Thanks for the response, Ryan. I'll look into our git line ending settings.
     
  4. lovexbma

    lovexbma

    Joined:
    Jul 1, 2016
    Posts:
    3
    How are AssetFileHashes calculated? From the result of my test.I found even with zero changes to our assets,the AssetFileHash seems to be different if we build our AssetBundles on different Mac.Would you please explain the
    principle of calculate AssetBundle hash.The options that we used:
    Code (CSharp):
    1. var options = BuildAssetBundleOptions.AppendHashToAssetBundleName |
    2.                           BuildAssetBundleOptions.DeterministicAssetBundle |
    3.                           BuildAssetBundleOptions.ChunkBasedCompression ;