Crash with custom UMG Viewport Widget

Is it possible to wrap game viewport in a UMG widget? I have this custom widget class:


class MYPROJECT_API UMyViewportWidget : public UContentWidget

    UPROPERTY(EditAnywhere, Category = Appearance)
    FLinearColor BackgroundColor;

    virtual void ReleaseSlateResources(bool bReleaseChildren) override;

    void InitializeViewport();

    TSharedPtr<class SViewport> ViewportWidget;
    virtual TSharedRef<SWidget> RebuildWidget() override;



void UMyViewportWidget::ReleaseSlateResources(bool bReleaseChildren)

void UMyViewportWidget::InitializeViewport()
    UGameInstance* MyGameInstance = GetWorld()->GetGameInstance();
    SViewport* View = MyGameInstance->GetGameViewportClient()->GetGameViewportWidget().Get();

TSharedRef<SWidget> UMyViewportWidget::RebuildWidget()
    if (IsDesignTime())
        return SNew(SBox)
            SNew(STextBlock).Text(NSLOCTEXT("", "", "My Viewport"))
        ViewportWidget = SNew(SViewport);
        return ViewportWidget.ToSharedRef();

But I get the below crash. Attached image is the call stack.

Exception thrown at 0x00007FFB433704DA (UE4Editor-Engine.dll) in UE4Editor-Win64-DebugGame.exe: 0xC00000FD: Stack overflow (parameters: 0x0000000000000001, 0x0000002BB8A03F60).
Unhandled exception at 0x00007FFB433704DA (UE4Editor-Engine.dll) in UE4Editor-Win64-DebugGame.exe: 0xC00000FD: Stack overflow (parameters: 0x0000000000000001, 0x0000002BB8A03F60).;base64

I added the viewport widget to UMG and called InitializeViewport and above crash happens.

Hi! Have you possibly been able to find a solution for this?

I have been researching wrapping the game view in a widget, and can’t seem to find any good information. Seems like a pretty standard requirement for any strategy/tactical game or anything elses UI-heavy, yet there doesn’t seem to be any support for it.

I’m sure there is a way to do it reliably, and I’ve been attempting to something similar to your code, but no working result yet. Therefore I’m really hoping for some help from others who have run into this issue…

@Kassym123 I managed to put the current viewport into a UMG widget. You can find it out here: Game Viewport Widget in Code Plugins - UE Marketplace