Comparing Table Entry References

Hi,

Let’s say we have object A and B that both have a localized string. I want to compare these objects, and they are considered “same” if they have matching localization entries.

I’m trying to compare LocalizedString.TableEntryReference.KeyId and Key.
However, sometimes the other one as Key (the string) defined and KeyId being 0 and the other has it the other way around.

Why is this? It doesn’t seem to be consistent as this started now causing problems for me suddenly as things aren’t considered the same suddenly.

An entry can be referenced in 1 of 2 ways, the Key or the Key ID.
https://docs.unity3d.com/Packages/com.unity.localization@1.4/manual/TableEntryKeys.html

Setting through the inspector is done through Key Id, through script can be either depending on how you set the reference.

If this is an editor script then the simplest thing would be to get the entry using the reference and compare that.
https://docs.unity3d.com/Packages/com.unity.localization@1.4/api/UnityEditor.Localization.LocalizationEditorSettings.html#UnityEditor_Localization_LocalizationEditorSettings_GetStringTableCollection_UnityEngine_Localization_Tables_TableReference_

Thanks for the reply.

Unfortunately it’s not editor script. More like comparing two abilities to see if they are the “same” (by just the localization reference).

What worked for now was to just use GetLocalizedString() and and compare the string values, as in my case they are unique.

You could first check the ReferenceType, if it matches then you are safe to compare the 2 Keys or Key Ids, if they are not the same then fallback to checking the entries.