- Vrealmatic
- Unreal Engine Wiki
- DesktopPlatform
Working with DesktopPlatform in Unreal Engine
How to work with DesktopPlatform features in Unreal Engine?

IDesktopPlatform
Open Explorer for browsing files on PC drive and return path of selected file
.h
#if WITH_EDITOR
/**
* <mark>Open Browsing Dialog in PC</mark>
*/
UFUNCTION(BlueprintCallable, Category="Import")
<strong>static FString BrowseFiles(FString PromptMessage, bool& bOutSuccess, FString& OutInfoMsg);</strong>
#endif.cpp
#if WITH_EDITOR
#include "IDesktopPlatform.h"
#include "DesktopPlatformModule.h"
FString UImportAsset::BrowseFiles(FString PromptMessage, bool& bOutSuccess, FString& OutInfoMsg)
{
bool bOpen = false;
TArray<FString> OpenFilenames;
FString ExtensionStr;
ExtensionStr += TEXT("CSV files|*.csv|");
IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
if (!DesktopPlatform){
bOutSuccess = false;
OutInfoMsg = FString::Printf(TEXT("Browsing files is supported on Desktop platform only - Please, fill the paths manually."));
return FString();
}
FString DefaultPath;
FString DefaultFile;
FString PickedFileName;
bOpen = <mark>DesktopPlatform->OpenFileDialog</mark>(
FSlateApplication::Get().FindBestParentWindowHandleForDialogs(nullptr),
*PromptMessage,
*DefaultPath,
*DefaultFile,
*ExtensionStr,
EFileDialogFlags::None, // allow select only one
OpenFilenames
);
if (bOpen)
{
bOutSuccess = (OpenFilenames.Num() == 1);
if(bOutSuccess) PickedFileName = OpenFilenames[0];
}
return PickedFileName;
}
#endif.Build.cs
if (Target.bBuildEditor == true)
{
PublicDependencyModuleNames.AddRange(
new string[]
{
"DesktopPlatform",
}
);
}

