What am I missing with TakeWidget?

In UE4 4.21.2 I am having an issue with the game crashing when I call UWidget::TakeWidget from my GameInstance.

Relevant header code

 UPROPERTY(EditAnywhere, BlueprintReadWrite)
 TSubclassOf<class UUserWidget> LoadingScreenWidget;

 UPROPERTY()
 UUserWidget* loadingumg;

 TSharedPtr<class SWidget> widgetptr;

Relevant implementation code (LoadingScreenWidget is set in BP, verified in the debugger that it is set)

loadingumg = CreateWidget(this, LoadingScreenWidget);
widgetptr = loadingumg->TakeWidget();
As far as I can see, this should be working based on examples written for older engine versions. If I follow the trace, at widget.cpp:720 the code attempts to access MyWidget, which is null.

UE4Editor_UMG!UWidget::TakeWidget_Private() [d:\build++ue4\sync\engine\source\runtime\umg\private\components\widget.cpp:720] UE4Editor_UMG!UWidget::TakeWidget() [d:\build++ue4\sync\engine\source\runtime\umg\private\components\widget.cpp:709] MyCustomGameInstance::BeginLoadingScreen()

UE4Editor_Engine!UEngine::LoadMap() [d:\build++ue4\sync\engine\source\runtime\engine\private\unrealengine.cpp:11810] UE4Editor_Engine!UEngine::Browse() [d:\build++ue4\sync\engine\source\runtime\engine\private\unrealengine.cpp:11527] UE4Editor_Engine!UGameInstance::StartGameInstance() [d:\build++ue4\sync\engine\source\runtime\engine\private\gameinstance.cpp:498]

UE4Editor!FEngineLoop::Init() [d:\build++ue4\sync\engine\source\runtime\launch\private\launchengineloop.cpp:3053]

UE4Editor!GuardedMain() [d:\build++ue4\sync\engine\source\runtime\launch\private\launch.cpp:161]

UE4Editor!GuardedMainWrapper() [d:\build++ue4\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:145]

UE4Editor!WinMain() [d:\build++ue4\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:276] UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:283]

kernel32

ntdll

I’m basing my assumption that this code should work on this question: How do you convert a UUserWidget to a SWidget? Needed for a loadingscreen. - UI - Epic Developer Community Forums

Is there some initialization that needs to be done so MyWidget is not null? Has anyone else had this issue?

How do you initiate UMG widget?

You can try to call RebuildWidget direcly