Custom Asset Filtering (GetAssetFilter)

As of UE 5.5, there is GetAssetFilter, this is great to enforce custom filtering of assets you can’t really do via the UPROPERTY line.
One use case i saw recently is for a DataTable filters to allow child row types, which is not possible with the default meta.

  UPROPERTY(EditAnywhere, Category="Data", meta=(GetAssetFilter="MyTableRowsFilter"))
    TObjectPtr<UDataTable> MyDataTable;

    UFUNCTION()
    bool MyTableRowsFilter(const FAssetData& AssetData);

The GetAssetFilter will go through all UObjects towards the outer object to find the matching function for example MyTableRowsFilters. Once found it will call this for filtering.

Heres an example filter i made

bool UMyObject::MyTableRowsFilter(const FAssetData& AssetData)
{
    FString Parent = FParentDataTableRow::StaticStruct()->GetPathName();
    static const FName RowStructureTagName("RowStructure");
    FString RowStructure;
    if (AssetData.GetTagValue<FString>(RowStructureTagName, RowStructure))
    {
        if (RowStructure == Parent)
        {
            return false;
        }

        // This is slow, but at the moment we don't have an alternative to the short struct name search
        UScriptStruct* RowStruct = UClass::TryFindTypeSlow<UScriptStruct>(RowStructure);
        if (RowStruct && RowStruct->IsChildOf(FParentDataTableRow::StaticStruct()))
        {
            return false;
        }
    }
    return true;
}

This allows the picking of DataTables that are or inherits from FParentDataTableRow. Struct example below

USTRUCT(BlueprintType)
struct FParentDataTableRow : public FTableRowBase
{
    GENERATED_BODY();

    
};
USTRUCT(BlueprintType)
struct FChildParentRow : public FParentDataTableRow
{
    GENERATED_BODY();

};

This is not possible any other way than this. But this is not required for FDataTableRowHandle as it does handle child structs!!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.