skip to Main Content

Creating a File Picker

In this post we’re going to see how to create a basic File Picker inside Unreal Engine. We’re going to use the built-in tools that the engine provides and read a text file.

[button size=”big” color=”black” link=”https://github.com/orfeasel/UE4-Cpp-Tutorials/tree/master/FilePicker”]Download the entire source code from my GitHub repo[/button]

Adding the required Dependencies

For this post I have created a C++ project using the 4.20 version of the engine. Then, I added the SlateCore dependency in the public module names in the <MyProject>.Build.cs file:

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay","SlateCore" });

Creating the file picker

Ideally, you will place the functionality of the file picker in a utility library so you can use it throughout your project. However I’ve added the code inside the character code just for demonstration purposes.

I have created two functions, one that is responsible for opening and displaying the file picker and one which is responsible for getting the contents of the selected file:

Before implementing the logic for each function, make sure to include the following header files in your class:

The reason we need to include them is so we can have access to the deskplatform code where the built-in file picker exists.

Here’s the implementation of each function:

After compiling my code, I created the following BP code to read the contents of the single file I selected:

(Click on image to enlarge in a new tab)

Here is how the file dialog looks from within the engine:

(Click on image to enlarge in a new tab)

It’s worth noting that depending on the files that you want to read your print/parse data function may differ from this post. If you want to be able to select any data type you can leave the file types string empty.

Avatar photo

This Post Has 12 Comments

    1. Hey, I’ve not tested yet, but I think this is because of a missing module linkage. It’s weird that there is no compile time error actually.

      I will try with
      PublicDependencyModuleNames.AddRange(new string[] { “Core”, “CoreUObject”, “Engine”, “InputCore”, “DesktopPlatform” });

      (SlateCore and HeadMountedDisplay are other modules, maybe useful for the author, but unnecessary for this tutorial)

      I will let you know if this works

  1. Is there any chance you could compile this as a plugin? I’m not familiar with C++, so this would be a huge help. Thanks!

  2. Hey, thank you for this it is really helpful! Right now I only have it working in PIE, do you know how I could modify this to work in the editor? Trying to build out some fool proof UI for getting different URI’s

  3. hey, package shipping filed error,
    UATHelper: Packaging (Windows(64位)): ERROR: Missing precompiled manifest for ‘DesktopPlatform’. This module was most likely not flagged for being included in a precompiled build – set ‘PrecompileForTargets = PrecompileTargetsType.Any;’ in DesktopPlatform.build.cs to override.
    Can You know how to setting ? Thanks for you

    1. For anyone else who reads this: look into PromptUserForDirectory. Not sure if it supports multiple filepath selection, though.

  4. The DesktopPlatform module is a Developer module, the EULA version of the engine does not include Developer modules for Shipping builds. An Epic employee recommends building a custom UMG/Slate file picker that relies on IPlatformFile system instead.

  5. Very useful. Just a note, rather than declaring a specific windows handle, which didn’t seem to work for me in 4.24, let Slate handle that by using this code as the first argument in the OpenFileDialogue:

    FSlateApplication::Get().FindBestParentWindowHandleForDialogs(nullptr)

    1. Daniel, thank you a million times,

      I’ve been trying to get a viewport window handle in the editor for a couple hours now and your SlateApplication WindowHandle get worked like a charm. Cheers!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back To Top