LocalizedString lose entry reference

Hi, i’m adding localization (with the unity localization package) to a game that has a small dialogue system. Dialogues are scriptable objects assets inside a folder and the Dialogue class has a text member that was of string type and now is of LocalizedString type. I made an editor script that searches for all dialogues in a folder and then adds an entry in the StringTable with the key being the name of the dialogue asset file. That works fine and all dialogues get a reference to its entry, when i hit play dialogues are shown fine also, but when i quit play all dialogues lose the reference to its entry. This is the code of the editor script:

public static void UpdateDialogueTable()
{
    var selected = Selection.activeObject;
    bool isFolder = AssetIsFolder(selected);
    if (isFolder)
    {
        string folderPath = AssetDatabase.GetAssetPath(selected);
        string[] guids = AssetDatabase.FindAssets("t:Dialogue", new []{folderPath});

        var table = LocalizationEditorSettings.GetStringTableCollection("Dialogues").GetTable("es");
        var stringTable = table as StringTable;
        var sharedData = stringTable.SharedData;
                
        string sharedDataPath = AssetDatabase.GetAssetPath(sharedData);
        string sharedDataGuidString = AssetDatabase.AssetPathToGUID(sharedDataPath);
        var sharedDataGuid = Guid.Parse(sharedDataGuidString);
                
        foreach (var guid in guids)
        {
            string path = AssetDatabase.GUIDToAssetPath(guid);
            var dialogue = AssetDatabase.LoadAssetAtPath<Dialogue>(path);
            long keyId = stringTable.SharedData.GetId(dialogue.name);

            dialogue.LocalizedText.SetReference(sharedDataGuid, keyId);
        }
    }
    else
    {
        Debug.Log("Not a folder");
    }
}

Also, there are 2 dialogues that i set their entries manually and they don’t lose their references, only those that get their references through the editor script.

1 Answer

1

Hi,
If you are modifying ScriptableObject assets then you need to set them dirty or the changes will not be serialized and will be lost the next time the asset is loaded.

EditorUtility.SetDirty(dialogue);

For further Localization related questions this is the best place:
https://forum.unity.com/threads/release-announcements-and-notes.597262/