Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question LocalizedString.TableEntryReference is missing Key value

Discussion in 'Localization Tools' started by mrCharli3, Jun 1, 2023.

  1. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    956
    When I try to get the key from a
    LocalizedString.TableEntryReference
    I only get the int id, not the string Key. Why is that and how do I make sure the Key field gets a value?

    I want to get the Key I've specified in the Localization table.
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,820
    We have 2 different ways to reference a TableEntry. https://docs.unity3d.com/Packages/com.unity.localization@1.4/manual/TableEntryKeys.html

    We can either reference the entry by Name or its Id. When you set the value in the inspector we use the Id value as its much safer, it means you can change the name of the Key later and won't lose any references to it.
    The TableEntryReference will only be 1, either the Key or the Id.
    You can check which it holds by checking its ReferenceType field.
    If the reference is using the Id then you can find its name by calling ResolveKeyName, you will need a reference to the SharedTableData as there's not enough information in the reference for it to figure out the name itself(it doesn't know what table it belongs to.)

    If you need it at runtime you can call GetTable using the TableReference and then use the SharedTableData in the table to get the name. If this is Editor then you can use the LocalizationEditorSettings to get the collection and its SharedTableData.
     
  3. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    956
    Thank you! I figured as much but got a bit confused since it works for other rows in the string table. Not sure why some use Name and some use ID? I'm accessing them in the same way.
     
    Last edited: Jun 1, 2023
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,820
    Did you set them via script? They should all be IDs if set via the inspector.