Is it safe StringToHash() to use in Unity?

Posted by Sebastian Krysmanski on Game Development See other posts from Game Development or by Sebastian Krysmanski
Published on 2014-05-31T10:39:05Z Indexed on 2014/05/31 16:06 UTC
Read the original article Hit count: 280

Filed under:
|

I'm currently browsing through the Unity tutorials and saw that they're recommending to use Animator.StringToHash("some string") to created unique ids for animation properties (see here).

Since I'm a programmer, to me the word "hash" doesn't represents something unique. Like the Java documentation for hashValue() states:

It is not required that if two objects are unequal [...], then calling the hashCode method on each of the two objects must produce distinct integer results.

So, according to this (and my definition of "hash"), two strings may have the same hash value. (You can also argue that there are an infinite number of possible strings but only 2^32 possible int values.)

So, is there a possibility that StringToHash() will give me an id that actually belongs to another property (than the one I requested the hash for)?

© Game Development or respective owner

Related posts about unity

Related posts about scripting