UMG NativeWidgetHost wont display my content

hi all,

i have made a custom viewport widget to just show a mesh. it’s pretty much a copy and paste of the viewport widget and viewport client from the static mesh editor, with just minimal code to get it up and running.

i can get it to show in the game viewport with:

FSlateRenderTransform trans(FScale2D(0.5, 0.5));
GEngine->GameViewport->AddViewportWidgetContent(
SNew(SWeakWidget).PossiblyNullContent(MeshViewport.ToSharedRef()).RenderTransform(trans));

but if i try to display it in a umg NativeWidgetHost with this code:

NativeWidget->SetContent(SNew(SWeakWidget).PossiblyNullContent(MeshViewport.ToSharedRef()));

it doesn’t show, the native widget just shows the default content.

any help is appreciated.

Solved

I think it was that the SetContent functions needs to be called before my umg hud which holds the NativeWidgetHost is added to the viewport.

A work around I’ve found is to remove and then readd the UNativeWidgetHost from its parent after calling SetContent. This causes UNativeWidgetHost::RebuildWidget to be called, which causes the native widget set by SetContent to be used.

thanks, i will try that.

How did you fix this? I have the same problem here and I cant get it working…