File Dialog from C++ in EditorUtilityWidget

Hello everyone, I’ve been banging my head on the walls all day yesterday and found nothing at all.

What I’m trying to do is using a blutility to open a file dialog so I can import meshes from the hard drive and set them in a level. I can open the file dialog while the game is running but it’s not really what I want…

I have been searching how to use the GEditor but have no clue. I’ve tried including “Editor/EditorEngine.h” like mentionned herewhich seems to be the class of GEditor, but I don’t find it anywhere.
And I’m not even sure that’s what I need but I found nowhere except here where to do this.

Anyone have any idea how I could do this ?

Thanks in advance for any help or documentation, I’m desperate…

I found it on a chinese website !

In case anyone is interested :

#include "DesktopPlatform/Public/IDesktopPlatform.h"
#include "DesktopPlatform/Public/DesktopPlatformModule.h"
#include "Engine/GameEngine.h"
#include "EngineGlobals.h"
#include "SlateCore.h"
#include "Runtime/Engine/Classes/Engine/GameViewportClient.h"
#include "Framework/Application/SlateApplication.h"

void UDREditorWidgetClass::OpenFileDialog(const FString& DialogTitle, const FString& DefaultPath, const FString& FileTypes, TArray<FString>& OutFileNames) {
    void* ParentWindowPtr = FSlateApplication::Get().GetActiveTopLevelWindow()->GetNativeWindow()->GetOSWindowHandle();
    IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
    if (DesktopPlatform)
        uint32 SelectionFlag = 1; //A value of 0 represents single file selection while a value of 1 represents multiple file selection
        DesktopPlatform->OpenFileDialog(ParentWindowPtr, DialogTitle, DefaultPath, FString(""), FileTypes, SelectionFlag, OutFileNames);

This does exactly what I needed (I’ve included all my imports but some of them are probably useless in this context)

Hope this helps someone one day !

1 Like