How to clear all the entries from an AssetTableCollection using the API?


I want to remove all the entries from my AssetTableCollection using the API (Addressables v1.18.16), can anyone point me in the right direction? I was able to get the table itself, now all I need is to find a suitable method/function to delete all the entries.

We dont have a single clear API to do this. What is the reason you want to clear them all?

If you are in Editor then I would do something like this:

public static void ClearAll()
{
    var collection = LocalizationEditorSettings.GetAssetTableCollection("My Assets");
    foreach(var table in collection.AssetTables)
    {
        foreach(var tableEntry in table.Values)
        {
            // Remove the asset from Addressables
            if (!string.IsNullOrEmpty(tableEntry.Guid))
            {
                collection.RemoveAssetFromTable(table, tableEntry.Key);
            }
        }

        // Clear all entries
        table.Clear();
        EditorUtility.SetDirty(table);
    }

    // Clear all keys
    collection.SharedData.Entries.Clear();
    EditorUtility.SetDirty(collection.SharedData);
}

Ill add a task to add a clear API for the future.

Thank you! This is exactly what I was looking for.

I thought I was wrong because I tried to look in the docs many times but I can’t find a method to do this.

I am in the process of creating menu items in the editor to automate my workflow. And addressables and localization are parts of them.

That would be swell, thank you!

Btw, here’s the modified code, the code above produces some errors. Fixed them in here. Hope this helps.

public static void ClearAll(AssetTableCollection assetTableCollection) {
    var collection = assetTableCollection;
    var tables = collection.AssetTables.ToArray();
    foreach(var table in tables) {
        var tableEntries = table.Values.ToArray();
        foreach(var tableEntry in tableEntries) {
            // Remove the asset from Addressables
            if (!string.IsNullOrEmpty(tableEntry.Guid)) {
                collection.RemoveAssetFromTable(table, tableEntry.KeyId);
            }
        }

        // Clear all entries
        table.Clear();
        EditorUtility.SetDirty(table);
    }

    // Clear all keys
    collection.SharedData.Entries.Clear();
    EditorUtility.SetDirty(collection.SharedData);
}