Search Unity

Question Building asset bundles on different machine/Unity version results in different hash

Discussion in 'Addressables' started by jing-cong, Apr 6, 2021.

  1. jing-cong

    jing-cong

    Joined:
    Aug 7, 2020
    Posts:
    3
    Recently I'm trying to load asset bundles that are built by cloud machines and got errors.
    I tracked this issue and found that the asset bundles built by the cloud machine got a different hash from my local machine.

    Then I tried a different OS or unity version. At first, I found out that scene files will be different while being built in different OS, which causing the hash to get different.
    But after testing more, things got weird. The hash can be different in different OS, or Unity versions, no matter it is a scene file or a common asset. Sometimes it can be the same even in a Mac OSX 10.14 machine and a Windows10 machine, but different in a Mac OSX 10.14 mache and a Mac OSX 10.15 mache.
    The hash also got different in Unity 2019.4.3.f1 and Unity 2019.4.21.f1, on the same machine.

    Does anyone know what could be causing these hashes to be different? Or know of a solution to make the same project can always get the same asset bundles.

    I've read a thread about this.
    https://forum.unity.com/threads/bui...ent-machine-results-in-different-hash.703793/
    In this thread, the author said that he solves this problem by ensuring that all our machines are using the same architecture(32bit/64bit). But in my case, the machines I'm using are all 64bit.
     
    Last edited: Apr 6, 2021
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,822
    Hey there! I'll bounce this off of the team for their input. Which version of Addressables are you using?
     
  3. jing-cong

    jing-cong

    Joined:
    Aug 7, 2020
    Posts:
    3
  4. andymilsom

    andymilsom

    Unity Technologies

    Joined:
    Mar 2, 2016
    Posts:
    294
    When building on different machines, some bundles resulting in different hashes is hard to determine if there is a problem from your description.
    Chances are that these bundles contain shader?
    Shader compilation is not easy to be deterministic as there are aspects outside of our control. Rounding changes on values can differ when compiling between hardware. As this results in a different binary of the compiled shader, it then results in a different bundle hash.
    The most reliable way to keep this from happening, is to build from the same machine.

    Building with different unity versions is expected to result in different bundles. The bundles include the Unity version in the AssetBundle header and results in a different binary.
     
    mulova likes this.
  5. jing-cong

    jing-cong

    Joined:
    Aug 7, 2020
    Posts:
    3
    Thank you for your reply.

    Unfortunately, in my test project, shaders built by Addressables are deterministic.
    Scenes, textures in Android and WebGL, sounds are not deterministic.
    Textures seem to be affected by this issue:
    https://issuetracker.unity3d.com/is...diferent-editor-versions-or-operating-systems

    >> The most reliable way to keep this from happening is to build from the same machine.
    Here is the problem:
    If I use cloud service, a new OS is installed when starting a new build.
    In this case, can I get a reliable build result? Or maybe it is better to use asset bundles without cloud service?
     
  6. cadxplore

    cadxplore

    Joined:
    Sep 4, 2019
    Posts:
    17
    I'm facing the same problem too and I noticed it happens on Android build, while the iOS build seems to be working fine.
    I would like to ask how important it is for us to append hash after the filename? Because the workaround that I use is by setting Bundle Naming Mode to Filename only. But I'm not sure how much do I need to sacrifice without the hash.

    EDIT: Sorry I just tested the workaround it doesn't work either because now I'm receiving CRC mismatch error!
     
    Last edited: Apr 23, 2021
  7. mulova

    mulova

    Joined:
    Apr 14, 2011
    Posts:
    62
    Even in the same machine(macOS Big Sur) with the same project name ( prj_ios and test/prj_ios. cloned by git), 'Update a previous build' generates new hashes for the bundles except the builtinshader bundle (I'm using addressables 1.17.17) even there are no changes for the assets.
    To share the build cache, I used Build Cache Server.
    Is there any way or plan to fix this?
     
  8. andymilsom

    andymilsom

    Unity Technologies

    Joined:
    Mar 2, 2016
    Posts:
    294
    This will depend on what the cause is, you said the builtinshader bundle didnt change hash. so probably not shader indeterminism.
    Best way to go about doing this is to find out what Assets actually changed. Best way to do this is probably to hook into the BuildScript in Addressables with a script I made to look into similar cases which you can find here https://gist.github.com/AndyMUnity/2338dd468315c26e295e8014545afc22 (It is not fully working, as it doesn't work for Scenes, but will probably work well for your needs), or can extract the bundles and compare them (https://support.unity.com/hc/en-us/articles/217123266-How-do-I-determine-what-is-in-my-Scene-bundle-) if you cannot duplicate the issue with fresh builds.
    There are some known issues with indeterminism, astc textures across CPU's that is being looked into and shaders which is trickier.
    Once you know what Assets have changed their binary and can then see what causes it.
     
    hamza_unity995 and mulova like this.
  9. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    Hey all, just wanted to chime in and say that we're going to add an option to the AddressableAssetSettings object to strip the Unity version from the AssetBundle header during a build. Hope this helps. You should see this option in Addressables 1.18.5+