Search Issue Tracker

Active

Fixed in 2022.3.8f1, 2023.1.10f1, 2023.2.0b2, 2023.3.0a1

Under Consideration for 2021.3.X

Votes

1

Found in

2021.3.25f1

2022.2.19f1

2023.1.0b16

2023.2.0a14

2023.3.0a1

Issue ID

UUM-35766

Regression

No

AssetBundle incremental build needs to detect script namespace/assembly change

--

-

Repro:
* Open the attached project (google drive link in first comment)
* Use Menu item to Build AssetBundles
* Change the namespace in MyScripteableObject.cs
* Use the Menu item to Build AssetBundles again
* Check the console

Expected: Both AssetBundles are rebuilt with new hashes.
Actual:
The test code detects that the bundle_sobject was rebuilt, but has exact same hash.
{code:java}
Collecting results of new Build:
[Rebuilt, identical content]: bundle_prefab
Now: Unity hash: 31a95ff8d11850cd72fc866665a946e1 Content MD5: 62aa5b9ff9a5df569c36693a7ba8cdb2 CRC: CEF9438B Write time: 5/11/2023 1:41:42 PM
Was: Unity hash: 31a95ff8d11850cd72fc866665a946e1 Content MD5: 62aa5b9ff9a5df569c36693a7ba8cdb2 CRC: CEF9438B Write time: 5/11/2023 10:28:21 AM
*WARNING* [New CRC content, but unchanged hash]: bundle_sobject
Now: Unity hash: e540d1829f3b94f916bdf7072417565f Content MD5: 18f145651eb6154fbbd49d9395fa1091 CRC: D35309F1 Write time: 5/11/2023 1:41:42 PM
Was: Unity hash: e540d1829f3b94f916bdf7072417565f Content MD5: 614754f5ff31c1ef0e7c87dd1a7d1e52 CRC: 328DB0D0 Write time: 5/11/2023 10:28:21 AM
{code}
Reproduced on 2021.3 and 2022.2 This code has not changed, so it should also reproduce in 2023.X

Detail:

This is a bug in the incremental build calculation for Native AssetBundles.
The bundle is rebuilt because the TypeTreeHash is different. But the main hash is unchanged. This causes serious problems if users use that hash as a version identifier.

Workaround:
Because the code actually does rebuild the bundle the main workaround is to use a different value as the version hash, not the hash that Unity exposes.

I've written a detailed description of problem and ways to avoid it, and the sample test code in the repro project for detecting it.
[https://forum.unity.com/threads/about-incremental-build-and-asset-bundle-hashes.1436032/]

But actually fixing the bug is also a good idea as we have such a clear understanding of it now.

Backporting:
We should only backport this for existing LTS versions if we add a new flag to make it opt-in. To keep such flags to an absolute minimum we should fix multiple issues at the same time. UUM-2259, UUM-16394, UUM-34924, BPSBP-764 call into that category

  1. Resolution Note (fix version 2023.3.0a1):

    BuildPipeline.BuildAssetBundles now generates its hash based on the content rather than the inputs. The input hash is now tracked as a separate hash value inside .manifest files. In 2023.X branches versions this is always enabled. There is a new BuildAssetBundleOptions.UseContentHash flag added, so that users of earlier Unity versions can start using this feature in an opt-in fashion, then the flag is ignored and assumed enabled when upgrading to 2023 versions.

  2. Resolution Note (fix version 2023.1.10f1):

    BuildPipeline.BuildAssetBundles now generates its hash based on the content, rather than the inputs. The input hash is now tracked as a separate hash value inside .manifest files. In 2023.X branches versions this is always enabled. There is a new BuildAssetBundleOptions.UseContentHash flag added, so that users of earlier Unity versions can start using this feature in an opt-in fashion, then the flag is ignored (and assumed enabled) when upgrading to 2023 versions.

  3. Resolution Note (fix version 2022.3.8f1):

    With this fix a new BuildAssetBundleOptions.UseContentHash flag is introduced. When specified, Unity will correctly detect the change in script's namespace or assembly. It will also fix issues with "hash conflicts". This fix requires the flag because we do not want to force all existing AssetBundles that are already build with 2022.3 to be rebuilt, hence it is an "opt-in" fix.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.