Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Feedback TMP_SpriteAsset.GetSpriteIndexFromName not working (fix inside)

Discussion in 'Unity 6 Beta' started by Peter77, Feb 25, 2024.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,640
    I upgraded Unity and noticed that TMP_SpriteAsset.GetSpriteIndexFromName no longer works, it returns -1 always.

    The problem is that
    GetSpriteIndexFromName
    uses:
    Code (CSharp):
    1. int hashCode = TMP_TextUtilities.GetSimpleHashCode(name);
    But the code in
    UpdateLookupTables
    that builds the
    m_NameLookup
    table uses:
    Code (CSharp):
    1. int nameHashCode = TMP_TextUtilities.GetHashCode(m_SpriteCharacterTable[i].name);
    2. if (m_NameLookup.ContainsKey(nameHashCode) == false)
    3.    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.
     
    lilacsky824 and Anthiese like this.
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,640
    Was this message forwarded to the person or team who works on TextMeshPro?
     
  3. alan10801

    alan10801

    Joined:
    Sep 20, 2019
    Posts:
    5
    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)
     
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,640
    @HugoBD-Unity For your information, please see first post in thread.
     
  5. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    513
    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.