Programmatically Added Entries Not Showing Up

Hi,

so I’ve got some code that goes through some external assets, adds the entries to the database, and then assigns the newly added entry to a new asset’s localized string.

This is all working fine, except one really annoying issue: after the export step, the table is full of keys, but shows no values.

If I close the editor and relaunch, the values are in the string table.

Is there some way to make the tables refresh properly without restarting the editor?

Can you show the script? Does the table update if you close the table window and reopen it or does it have to be an editor restart?

public static LocalizedString UpdateOrAddStringToGenerated(string value, string id)
    {
        var tableCollection = LocalizationEditorSettings.GetStringTableCollection(Singleton.GeneratedTableName);
        StringTable table = GetGeneratedTable();

        foreach (var kvp in table)
        {
            if (kvp.Value.Key == id)
            {
                kvp.Value.Value = value;
                return new LocalizedString(Singleton.GeneratedTableName, id);
            }   
        }

        table.AddEntry(id, value);
        Debug.Log("added: " + value + " to loc database");
        return new LocalizedString(Singleton.GeneratedTableName, id);

    private static StringTable GetGeneratedTable()
    {
        var tableCollection = LocalizationEditorSettings.GetStringTableCollection(Singleton.GeneratedTableName);
        return tableCollection.GetTable("en") as StringTable;
    }
    }

These are the two relevant methods. As for when it shows up, it will only update after I do a full editor restart. Merely reopening the table doesn’t display the inserted text

When you add a new entry to the table call EditorUtility.SetDirty on the table and it’s shared table data asset.

Ah, ty, that seems to have done it. I was setting the shared table data as dirty in a different method, but not the table. Once I did that, it started updating correctly in editor

1 Like