Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Hansol Steve Kim · May 04, 2016 at 04:18 PM · methodhash

Does NOT Hash128.Parse() method return UNIQUE hash?

Hi Dev! For using Hash128 in my code, I tested some simple code. But result was a little weired. I guessed Hash128.Parse() method returns UNIQUE hash (Hash128), but it didn't.

Test code is below.

     Hash128 a = Hash128.Parse("TestA");
     Hash128 b = Hash128.Parse("TestB");
     
     Debug.Log( "a: " + a.ToString() );
     Debug.Log( "b: " + b.ToString() );
     Debug.Log( "equal? " + a.Equals( b ) );

And here is result log.

     a: 0e000000000000000000000000000000
     b: 0e000000000000000000000000000000
     equal? True

Do I use Hash128 wrong?

If do that, Please tell me how to use Hash128 correctly or hash function used for Hash128. Thx!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tomerpeledNG · Oct 20, 2017 at 08:49 PM 0
Share

I know, that this question is old, but still, I'm encountering the exact results. Isn't Hash128.Parse unique?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by tgrotte · Oct 08, 2020 at 09:49 PM

Here's an update. It looks like you can use Hash128's Compute method with one of the various overloads. @Bunny83 It appears that Unity is using the SpookyV2 hashing algorithm, also mentioned in the link I shared.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Oct 10, 2020 at 12:53 AM 1
Share

Great, so they finally added the actual Compute method for us to use and updated the documentation.

avatar image tgrotte Bunny83 · Oct 12, 2020 at 02:24 PM 0
Share

I recently came across documentation from Unity stating that the hash values Unity generates for asset bundles, as listed in the asset manifest, are not reliable and should not be used as version numbers to the Caching system. This is consistent with my experience- I've seen many times different content being assigned the same hash value from Unity. Do you use their hashes with the quirky behavior or make your own version number? I'm curious what experienced developers are using. I'm wondering if I could use this Hash128.Compute method after the build process is complete to make my bundle version numbers or if it will suffer from the same issue. I can certainly test that out. Thanks @Bunny83.

avatar image
0

Answer by Bunny83 · Oct 21, 2017 at 02:24 PM

No Hash128 is just a struct to store an AssetBundle hash. It can't calculate a new hash. Parse is just the opposite of ToString. So all "Parse" does is convert the string representation of a hash back into the numeric struct representation. Again, it does not calculate a hash.

Just to make it more clear, here's an example. I just created an arbitary hash manually and let it convert to string:

 var h = new Hash128(0x12345678,0xABCDABCD,0xDEADBEAF, 0x55AA55AA);
 string str = h.ToString();
 Debug.Log("str: " + str);
 var h2 = Hash128.Parse(str);
 Debug.Log("equal? " + (h == h2));

In the console you will see:

 str: 78563412cdabcdabafbeaddeaa55aa55

and

 equal? True

As you can see ToString simply converts the 4 uint values into hex and Parse simply does the inverse and converts the hexadecimal representation back to a hash.

In your case "TestA" is not a valid hex string. However it actually detected the "e" in your string as hex digit which is the only one it can read.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Oct 21, 2017 at 02:49 PM 0
Share

Apart from that it should be clear that any hashing algorithm can't create a "unique" hash for a message that is longer than the hash. It's simply impossible. Good hashing algorithms however should avoid collisions of similar messages. However there are always many many messages which will result in the same hash, but those messages are completely different. A 128 bit hash has as many digits as a GUID / UUID. So the probability that one hash is equal to another is very very small.

But again, Unity's Hash128 struct is just a numerical representation of a hash and does not allow to compute a hash. Unity uses this struct for internal asset management and to identify assetbundles. It's returned by methods like "UnityEditor.AssetDatabase.GetAssetDependencyHash". There is currently no method to manually calculate such a hash of arbitrary data. It's not even specified what algorithm Unity uses internally. If you need a hashing algorithm at runtime you should first look for a suitable hashing algorithm and then look for a .NET / $$anonymous$$ono implementation

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

56 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 4.6.8 Facebook SDK 6.2.2 - Android Build Facebook Settings don't give the hash 0 Answers

What go inside the brackets in voids? 1 Answer

How to destroy ParticleSystem clone? 3 Answers

Make a virtual method englobing a child override function 0 Answers

Upon building Unity game it always change some DLL files even if I have not done changes to it. Is there a way to prevent it? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges