Tables breaking when reloading domain

I’m generating a new AssetTableCollection and and AssetTable for each locale with generated voiceover AudioClips based on a StringTable and I’m running into a strange issue.

When I change any script and Unity reloads the domain 2 things can happen:

Either the script is missing from my AssetTable.

Or the table no longer belongs to a collection.

I’m completely at a loss as to why this is happening. Is this a bug or am I doing something wrong?
I have also noticed that the icons of my generated AssetTables are different from the ones created using the Localization Tables editor window.

I’m using Unity 2022.3.23 and Localization 1.5.2
And generating the tables like this:

        private static AssetTableCollection GetOrCreateAssetTableCollection(string tableCollectionName)
        {
            AssetTableCollection newAssetTableCollection = LocalizationEditorSettings.GetAssetTableCollection(tableCollectionName);
            if (newAssetTableCollection == null)
            {
                Debug.Log($"Creating new AssetTableCollection: {tableCollectionName}");
                newAssetTableCollection = LocalizationEditorSettings.CreateAssetTableCollection(tableCollectionName, Path.Combine(BUTXRConstants.Paths.Localization, tableCollectionName), LocalizationSettings.AvailableLocales.Locales);
                if (newAssetTableCollection == null)
                {
                    Debug.LogError($"Failed to create AssetTableCollection: {tableCollectionName}");
                }
                else
                {
                    EditorUtility.SetDirty(newAssetTableCollection);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
                }
            }
            else
            {
                Debug.Log($"Using existing AssetTableCollection: {tableCollectionName}");
            }
            return newAssetTableCollection;
        }
        private static AssetTable GetOrCreateAssetTable(string tableName, Locale locale)
        {
            AssetTable assetTable = _assetTableCollection.GetTable(locale.Identifier) as AssetTable;

            if (assetTable == null)
            {
                Debug.Log($"AssetTable not found. Creating new AssetTable for {tableName} and locale {locale.Identifier.Code}");

                assetTable = _assetTableCollection.AddNewTable(locale.Identifier) as AssetTable;

                if (assetTable == null)
                {
                    Debug.LogError($"Failed to create new AssetTable for {tableName} and locale {locale.Identifier.Code}");
                    return null;
                }

                SaveTable(assetTable);
            }
            else
            {
                Debug.Log($"Using existing AssetTable for {tableName} and locale {locale.Identifier.Code}");
            }

            return assetTable;
        }
private static void SaveTable(AssetTable assetTable)
{
    EditorUtility.SetDirty(assetTable);
    EditorUtility.SetDirty(assetTable.SharedData);
    EditorUtility.SetDirty(_assetTableCollection);

    AssetDatabase.SaveAssets();
    AssetDatabase.Refresh();
           
LocalizationEditorSettings.EditorEvents.RaiseCollectionModified(null, _assetTableCollection);
}

That does sound strange.
I dont see why the script would go missing from the asset. Typically this is because the script meta file has changed (guid change) or the script is no longer present/compiling in the project.

Are you able to submit a simple bug report so I can try to reproduce it myself? Unity QA: Building quality with passion

Please don’t do this:

Replace it with this:

AssetDatabase.SaveAssetIfDirty(newAssetTableCollection);

Since this collection was “created” it is dirty to begin with, and Refresh is simply and utterly unnecessary.

Likewise, check if you really need to manually mark all the assets as dirty in your SaveTable method. It depends on what these classes are and how they are modified but if changes are saved without manually marking them dirty, it avoids unnecessary serialization of these objects.

Again, only save the necessary assets, here I would expect saving assetTable also serializing SharedData because it is part of assetTable:

AssetDatabase.SaveAssetIfDirty(assetTable);
AssetDatabase.SaveAssetIfDirty(_assetTableCollection);

Refresh may sometimes seem to be necessary to update the GUI but usually there’s a method to update just the GUI when it comes down to this.

Hi Karl,
After copying the entire assets folder in a new Unity project the LocalizationSettings asset had their script missing. I deleted that and my string table, recreated them from the editor window and now the generation of the new tables just works… not sure what went wrong but I’m unable to reproduce it for now. Will update if I come across this issue again.