Download

Can't get ParentWindowHandle

Problem: need to use OpenDirectoryDialog function.

I tried this: FDesktopPlatformModule::Get()->OpenDirectoryDialog()

But, can’t get ParentWindowHandle.

Tried to use this:


    TSharedPtr<SWindow> ParentWindow = FSlateApplication::Get().FindWidgetWindow(AsShared());
    const void* ParentWindowHandle = (ParentWindow.IsValid() && ParentWindow->GetNativeWindow().IsValid())
        ? ParentWindow->GetNativeWindow()->GetOSWindowHandle()
        : nullptr;

from Opening a file dialog from a plugin - UE4 AnswerHub thread. But get error “‘AsShared’: identifier not found”.

Also tried this:


const void* ParentWindowHandle = GEngine->GameViewport->GetWindow()->GetNativeWindow()->GetOSWindowHandle();

but still no luck.

AsShared isn’t free function and require object context: instance of class derived from TSharedFromThis<T>. (all classes derived from SWidget)

Are You trying pass a nullptr to OpenDirectoryDialog?

In case someone is going to have problems with this, solution described here: https://answers.unrealengine.com/questions/839322/unresolved-external-symbols.html

But basically you need to add “SlateCore” module to your *.Build.cs to to be able to use this:


...GEngine->GameViewport->GetWindow()->GetNativeWindow()->GetOSWindowHandle()

… as


const void* ParentWindowHandle

within this function:


 
 FDesktopPlatformModule::Get()->OpenDirectoryDialog(GEngine->GameViewport->GetWindow()->GetNativeWindow()->GetOSWindowHandle(), dialogTitle, defPath, folderPath); 

P.S. There’s probably more elegant way of doing this. But this worked for me.