TMP_SpriteAsset.GetSpriteIndexFromName not working (fix inside)

I upgraded Unity and noticed that TMP_SpriteAsset.GetSpriteIndexFromName no longer works, it returns -1 always.

The problem is that GetSpriteIndexFromName uses:

int hashCode = TMP_TextUtilities.GetSimpleHashCode(name);

But the code in UpdateLookupTables that builds the m_NameLookup table uses:

int nameHashCode = TMP_TextUtilities.GetHashCode(m_SpriteCharacterTable[i].name);
if (m_NameLookup.ContainsKey(nameHashCode) == false)
   m_NameLookup.Add(nameHashCode, i);

GetSimpleHashCode and GetHashCode generate different hash values, they’re not compatible with each other. Therefore GetSpriteIndexFromName returns -1 always, because the hash value can’t be found in the m_NameLookup table.

2 Likes

Was this message forwarded to the person or team who works on TextMeshPro?

Bump, I encountered the same issue. I found that forcibly converting it to uppercase allows it to return the correct value.

Version: Unity 6000.0.4f1

(Using GPT for translation might be inaccurate)

@HugoBD-Unity For your information, please see first post in thread.

Hi @Peter77 , thanks for raising the issue. Could you log a ticket using the Unity Bug Reporter (see this page). This is the best way to ensure we look into it.

I found this thread after doing the same code trace and wondering “why are they using different hashing functions for storage and lookup?”. This bug is still present in 6000.0.35 in 2025. My workaround was to hash the name using TMP_TextUtilities.GetHashCode and then use GetSpriteIndexFromHashcode to find the glyph in the sheet.

I filed a new bug report with an example string on the suspicion that maybe those two hash functions coincidentally returned the same values when the Unity team was trying to repro.

The bug is known and is fixed in 6000.2 and will not be back ported to 6000.0 Unity Issue Tracker - [TextMeshPro] Sprite index cannot be found when using the GetSpriteIndexFromName method

1 Like