Hi!
I’m working on converting our project to Addressables and I think there’s an issue with how the content catalog hashes lists of dependencies.
ContentCatalogData.SetData runs through all content entries and tries to find identical sets of dependencies by combining their hashes:
//seed and and factor values taken from https://stackoverflow.com/questions/1646807/quick-and-simple-hash-code-combinations
int hashCode = 1009;
foreach (var dep in entry.Dependencies)
hashCode = hashCode * 9176 + dep.GetHashCode();
The dependencies are then replaced with a single virtual one, which is retrieved using this hashCode. Any collision completely breaks the dependency graph serialized into ‘addressables_content_state.bin’ (I’m seeing ~10% collision rate on just over 300 entries). As a result, Addressable.LoadAsset fails for affected assets as it’s trying to load it from wrong asset bundle.
My quick fix is to increment hashCode until it maps to the correct list of dependencies:
bool isNew = false;
keys.Add(hashCode, ref isNew);
var deps = entry.Dependencies.Select(d => keyIndexToEntries[d][0]).ToList();
while (!isNew)
{
// Check for collision
var depsForHashCode = keyIndexToEntries[hashCode];
if (deps.Equals(depsForHashCode))
break;
hashCode++;
keys.Add(hashCode, ref isNew);
}
if (isNew)
{
//if this combination of dependencies is new, add a new entry and add its key to all contained entries
keyIndexToEntries.Add(hashCode, deps);
foreach (var dep in deps)
dep.Keys.Add(hashCode);
}
I’m on Addressables 0.7.5 and Unity 2019.1.0f2.
Hope this helps,
Dushan