Collection Manager's Get Assets in Collection always returns an empty array

In our project we have both standard and dynamic collections. I am writing an editor utility that needs to get the assets from these collections. This works fine for the standard collections, returning an array with the asset datas I expect. However, this always returns 0 results for all dynamic collections (tested with dozens of regular and dynamic queries). I have tried in both blueprint and python and get the same result in both.

Is there some sort of invocation of TestDynamicQuery() I should perform, and if so, how can I do that from blueprint/python? I could not see anything exposed to me like that. Alternatively, is this simply a bug, and I should expect Get Assets in Collection to handle this for me?

Thanks in advance,

Mike

Steps to Reproduce
Create a Dynamic Collection (here mine is called _Foliage_Main and a query like

!VFX AND (Path:‘/All/Game/VEG’…) Type=StaticMesh

Construct an editor utility blueprint as follows

The following blueprint prints:

LogBlueprintUserMessages: [None] _Foliage_Main - true - 0

Alternatively, create an editor utility blueprint and invoke the following via Python Execute Script

This will print (note RegularCollection1 and 2 are non-dynamic collections with 1 and 2 assets respectively), and show that this works fine for them):

LogPython: RegularCollection1 => 1

LogPython: RegularCollection2 => 2

LogPython: _Foliage_Main => 0

import unreal

cm = unreal.get_editor_subsystem(unreal.CollectionManagerSubsystem)
container = cm.get_base_game_collection_container()
print("Container:", container)
collections = cm.get_collections(container)

for c in collections:
  assets = cm.get_assets_in_collection(c)
  print(c.name, "=>", len(assets))

Hi,

It looks like the current implementation of GetAssetsInCollection doesn’t handle dynamic collections at all. You could work around this with a bit of C++ in a blueprint function library, something like this should work:

TArray<FAssetData> GetAssetsInDynamicCollection(FName Name, ECollectionShareType::Type ShareType)
{
    TSharedRef<ICollectionContainer> Container =
        FCollectionManagerModule::GetModule().Get().GetProjectCollectionContainer();
 
    TArray<FAssetData> AllAssets;
    IAssetRegistry::Get()->GetAssets(FARFilter(), AllAssets);
 
    TArray<FAssetData> Result;
    for (const FAssetData& Asset : AllAssets)
    {
        FAssetTextFilterContext Context(Asset);
        bool bPasses = false;
        if (Container->TestDynamicQuery(Name, ShareType, Context, bPasses) && bPasses)
        {
            Result.Add(Asset);
        }
    }
    return Result;
}

I’ve filed a bug report for this as well if you want to keep an eye on that for a potential fix, UE-396182.

Best,

Cody

Thanks Cody! We’re going to give this a try and will report back here.