Search Unity

Resolved Create new entry via script in editor - does not survive editor restart

Discussion in 'Localization Tools' started by shelim, Jul 29, 2021.

  1. shelim

    shelim

    Joined:
    Aug 26, 2017
    Posts:
    29
    Hello,

    We are working on simple dialogue system with editor support. We're using following code to create entries in UnityEditor programmatically:

    Code (CSharp):
    1. LocalizationSettings.StringDatabase.GetTable(ourTable).AddEntry(newKey, "");
    2.  
    3. var prop = so.FindProperty("Text");
    4.  
    5. prop.FindPropertyRelative("m_TableReference").FindPropertyRelative("m_TableCollectionName").stringValue = ourTable;
    6. prop.FindPropertyRelative("m_TableEntryReference").FindPropertyRelative("m_Key").stringValue = newKey;
    7.  
    And to edit them:

    Code (CSharp):
    1. if (newText != text)
    2. {
    3.     LocalizationSettings.StringDatabase.GetTable(_node.Text.TableReference).GetEntryFromReference(_node.Text.TableEntryReference).Value = newText;              
    4. }
    And this works correctly while editor is open. Closing the Unity Editor and re-oppening it discards all changes made by above code.

    I am almost sure that I miss a step to save our changes to addressables - but poking around docs, I could not find the relevent command.

    Can you point me in the right direction?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    Ah yes. When you make a change to the table you need to set it dirty with EditorUtility.SetDirty
    You will need to set the table and the shared table data dirty

    so
    Code (csharp):
    1. EditorUtility.SetDirty(ourTable);
    2. EditorUtility.SetDirty(ourTable.SharedData);
    We will try and automate this in the future but for now you need to manually set them dirty.
     
  3. shelim

    shelim

    Joined:
    Aug 26, 2017
    Posts:
    29
    Thank you for a very quick response :)

    Confirmed - it is working now.

    Just one more question - is there any way to set this field from a script?

    test.png
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    Yeah its the same as in the player.

    LocalizationSettings.SelectedLocale
     
  5. shelim

    shelim

    Joined:
    Aug 26, 2017
    Posts:
    29
    Thanks again :)
     
    karl_jones likes this.