i want to get all maps from DLCs.
i did google a lot,but i didt found the answer.
the thread above could not get map list from DLC
please help.
i want to get all maps from DLCs.
i did google a lot,but i didt found the answer.
the thread above could not get map list from DLC
please help.
here is my code to list all maps in a game,(the dlc map is under the plugin’s Content folder),but this is ugly:
TArray<FString> UYunTuLibraryBPLibrary::GetDLCLists()
{
TArray<FString> MapList;
auto ObjectLibrary = UObjectLibrary::CreateLibrary(UWorld::StaticClass(), false, true);
ObjectLibrary->LoadAssetDataFromPath(TEXT("/Game/Maps"));
TArray<FAssetData> AssetDatas;
ObjectLibrary->GetAssetDataList(AssetDatas);
TArray<FString> Names = TArray<FString>();
for (int32 i = 0; i < AssetDatas.Num(); ++i)
{
FAssetData& AssetData = AssetDatas*;
auto name = AssetData.AssetName.ToString();
MapList.Add(name);
}
bool bSuccessfulInitialization = false;
IPlatformFile* LocalPlatformFile = &FPlatformFileManager::Get().GetPlatformFile();
if (LocalPlatformFile != nullptr)
{
IPlatformFile* PakPlatformFile = FPlatformFileManager::Get().GetPlatformFile(TEXT("PakFile"));
if (PakPlatformFile != nullptr)
bSuccessfulInitialization = true;
}
if (bSuccessfulInitialization)
{
const TCHAR* cmdLine = TEXT("");
FPakPlatformFile* PakPlatform = new FPakPlatformFile();
IPlatformFile* InnerPlatform = LocalPlatformFile;
PakPlatform->Initialize(InnerPlatform, cmdLine);
FPlatformFileManager::Get().SetPlatformFile(*PakPlatform);
TArray<FString> Files;
Files = GetAllFilesInDirectory("Content/Paks/Mod/", true, "", "pak", true);
UE_LOG(LogTemp, Warning, TEXT("Mod Path:%s"), *(FPaths::GameDir() + "Content/Paks/Mod/"));
UE_LOG(LogTemp, Warning, TEXT("Pak File Num:%d"), Files.Num());
for (FString FilePath : Files)
{
FPakFile PakFile(*FilePath, false);
if (!PakFile.IsValid())
{
continue;
}
TArray<FString> Keys;
FString ContentKey;
PakFile.GetIndex().GenerateKeyArray(Keys);
for (int i = 0; i < Keys.Num(); i++)
{
if (Keys*.Contains("Content"))
{
ContentKey = Keys*;
break;
}
}
auto MapName = PakFile.GetIndex()[ContentKey];
MapName.GenerateKeyArray(Keys);
for (FString Temp : Keys)
{
Temp = FPaths::GetBaseFilename(Temp);
MapList.Add(Temp);
}
}
}
return MapList;
}