硬获取
UObjectLibrary* ObjectLibrary = UObjectLibrary::CreateLibrary(UUserDefinedStruct::StaticClass(), false, GIsEditor);
ObjectLibrary->LoadAssetDataFromPath(TEXT("/Game"));
TArray<FAssetData> AssetDatas;
ObjectLibrary->GetAssetDataList(AssetDatas);
for (const FAssetData& AssetData : AssetDatas)
{
UE_LOG(LogTemp, Error, TEXT("%s"), *AssetData.GetFullName());
}
软获取
TArray<FAssetData> AssetDatas;
FAssetRegistryModule& AssetRegistryModule = FModuleManager::GetModuleChecked<FAssetRegistryModule>("AssetRegistry");
FARFilter Filter;
Filter.PackagePaths.Add("/Game");
Filter.ClassNames.Add(UUserDefinedStruct::StaticClass()->GetFName());
Filter.bRecursivePaths = true;
Filter.bRecursiveClasses = true;
AssetRegistryModule.Get().GetAssets(Filter, AssetDatas);
for (const FAssetData& AssetData : AssetDatas)
{
UE_LOG(LogTemp, Error, TEXT("%s"), *AssetData.GetFullName());
}