Hi,
i want to check the assets for references but all referencers/dependencies are always zero. Can anyone help, please?
Here is my code:
void FCleanUp_PluginModule::SearchForAssets()
{
UE_LOG(LogTemp, Warning, TEXT(“Searching For Assets”));
//path to search
const FString DirectoryFolder = FPaths::ProjectContentDir();
//set FileExtension to NULL to get all files with any extension
const FString FileExtension = "";
//array to store found files
TArray<FString> FoundFiles;
//find files in contentbrowser
FPlatformFileManager::Get().GetPlatformFile().FindFiles(FoundFiles, *DirectoryFolder, *FileExtension);
FAssetRegistryModule& AssetRegistryModule = FModuleManager::GetModuleChecked<FAssetRegistryModule>("AssetRegistry");
for (int i = 0; i < FoundFiles.Num(); i++)
{
//check for dependencies
TArray<FName> HardDependencies;
AssetRegistryModule.Get().GetDependencies(*FoundFiles[i], HardDependencies,EAssetRegistryDependencyType::Hard);
TArray<FName> SoftDependencies;
AssetRegistryModule.Get().GetDependencies(*FoundFiles[i], SoftDependencies,EAssetRegistryDependencyType::Soft);
if (HardDependencies.Num() > 0)
{
UE_LOG(LogTemp, Warning, TEXT("hard dependencies found for %s"), *FoundFiles[i]);
}
if (SoftDependencies.Num() > 0)
{
UE_LOG(LogTemp, Warning, TEXT("soft dependencies found for %s"), *FoundFiles[i]);
}
//check for references
TArray<FName> HardReferecers;
AssetRegistryModule.Get().GetReferencers(*FoundFiles[i], HardReferecers,EAssetRegistryDependencyType::Hard);
TArray<FName> SoftReferencers;
AssetRegistryModule.Get().GetReferencers(*FoundFiles[i], SoftReferencers,EAssetRegistryDependencyType::Soft);
if (HardReferecers.Num() > 0)
{
UE_LOG(LogTemp, Warning, TEXT("hard reference found for %s"), *FoundFiles[i]);
}
if (SoftReferencers.Num() > 0)
{
UE_LOG(LogTemp, Warning, TEXT("soft reference found for %s"), *FoundFiles[i]);
}
}
}