Hi everyone,
I’m currently working on an Editor Utility module in Unreal Engine 5.5, and I’m trying to detect whether a specific content folder has assets in it.
I’m using the following API:
UFUNCTION (BlueprintCallable, Category="Editor Scripting | Asset") static bool DoesDirectoryHaveAssets ( const FString & DirectoryPath, bool bRecursive )
However, even though the folder I’m checking (e.g. /Game/MyFolder
) does contain assets, the function still returns false
.
void FSuperManagerModule::OnDeleteEmptyFolderButtonClicked() { FixUpRedirectors(); TArray<FString> FolderPathArray = UEditorAssetLibrary::ListAssets(FolderPaths[0], true, true); uint32 Counter = 0; FString EmptyFolderPathNames; TArray<FString> EmptyFolderPathArray; for (const FString& FolderPath : FolderPathArray) { if (FolderPath.Contains(TEXT("Developers")) || FolderPath.Contains(TEXT("Collections")) || FolderPath.Contains(TEXT("__ExternalActors__")) || FolderPath.Contains(TEXT("__ExternalObjects__")) ) continue; if (!UEditorAssetLibrary::DoesDirectoryExist(FolderPath)) continue; //DebugHeader::Print(5.f, FColor::Green, FolderPath ); if (!UEditorAssetLibrary::DoesDirectoryHaveAssets(FolderPath)) { EmptyFolderPathNames.Append(FolderPath); EmptyFolderPathNames.Append("\n"); EmptyFolderPathArray.Add(FolderPath); } } if (EmptyFolderPathArray.Num() == 0) { DebugHeader::ShowMessageDialog(EAppMsgType::Ok, TEXT("No empty folder found under select folder"), false); return; } EAppReturnType::Type Result = DebugHeader::ShowMessageDialog(EAppMsgType::OkCancel, TEXT("Empty folder found in :\n") + EmptyFolderPathNames + TEXT("Would you like to delete them"), false); if (Result == EAppReturnType::Cancel) return; for (const FString& EmptyFolder : EmptyFolderPathArray) { if (UEditorAssetLibrary::DeleteDirectory(EmptyFolder)) { ++Counter; } else { DebugHeader::PrintLog(TEXT("Failed delete ") + EmptyFolder); } } DebugHeader::ShowMessageDialog(EAppMsgType::Ok, TEXT("Successfully delete") + FString::FromInt(Counter) + TEXT(""), false); }
Totally same as the course,but.
As you can see, NewFolder/NewFolder1 is not Empty, however the ‘DoesDirectoryHaveAssets’ return false.
I want to know why and how to fix this.