Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

SharedTableData.GetId

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public long GetId(string key);

Parameters

Parameter Description
key The key to look up.

Returns

long The key's stable id, or 0 when it is absent.

Description

Returns the stable id for a key.

Returns 0 when the key is empty, null, or not present. Ids are stable across renames, so store the id rather than the key text when you need a reference that survives a rename.

Additional resources: SharedTableData.GetKey, SharedTableData.GetEntry

<para>Look up the id assigned to a key.</para>

using Unity.Localization;
using UnityEngine;

namespace Unity.Localization.Samples { public class SharedTableDataGetIdExample { public void Run() { var sharedData = ScriptableObject.CreateInstance<SharedTableData>(); sharedData.AddKey("GREETING");

long id = sharedData.GetId("GREETING"); // the key's stable id long missing = sharedData.GetId("UNKNOWN"); // 0

Debug.Log(id != 0); // True Debug.Log(missing); // 0 } } }