Unreal Engine calls local file picker (FileDialog)
Preface
When developing some desktop applications, you will need to use the engine to pick up the file content of the local disk. In conventional software, when you need to pick up disk content, you will wake up the file picker on the system desktop to complete it. How to wake up the desktop content picker in Unreal Engine? The operation is actually very simple.
Operation
- Import modules
"DesktopPlatform", "Slate", "SlateCore" are dependent modules and need to be imported.
|
|
- Execute the code to open the window
|
|
Header file
|
|
OpenFileDialog function parameter description:
- Parent node window handle
- File picker window title
- Picker default path
- Picker default lock file
- Picker file type constraint (If left blank, no constraint on type)
- Single file pick or multiple file pick, 0 single file pick, 1 multiple file pick
- After the pick is completed, the array where the picked content (path) is stored
Description
About pick type constraint
If you want to add type constraints, add them in the format of "description|type". Here are some examples:
- Pick only png type, "Image File|*.png" (refer to the screenshot above)
- Pick png type and jpg type, you can use semicolon separation, "Image File|*.png;*.jpg”
- Need to pick up image type, text type, json type, "Image File|*.png;*.jpg|Txt File|*.txt|Json File|*.json"
About call blocking
After the file picker is opened, the calling thread will be blocked. When the user selects the file, it will continue to execute.
Unreal Engine version: 4.27.2