Announcement

Collapse
No announcement yet.

Crash with custom UMG Viewport Widget

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Crash with custom UMG Viewport Widget

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

    Header
    Code:
    UCLASS()
    class MYPROJECT_API UMyViewportWidget : public UContentWidget
    {
        GENERATED_BODY()
    
        UPROPERTY(EditAnywhere, Category = Appearance)
        FLinearColor BackgroundColor;
    
        virtual void ReleaseSlateResources(bool bReleaseChildren) override;
    
    protected:
        UFUNCTION(BlueprintCallable)
        void InitializeViewport();
    
        TSharedPtr<class SViewport> ViewportWidget;
        virtual TSharedRef<SWidget> RebuildWidget() override;
    
    };
    Source
    Code:
    void UMyViewportWidget::ReleaseSlateResources(bool bReleaseChildren)
    {
        Super::ReleaseSlateResources(bReleaseChildren);
        ViewportWidget.Reset();
    }
    
    void UMyViewportWidget::InitializeViewport()
    {
        UGameInstance* MyGameInstance = GetWorld()->GetGameInstance();
        SViewport* View = MyGameInstance->GetGameViewportClient()->GetGameViewportWidget().Get();
        View->SetActive(false);
        ViewportWidget->SetContent(View->AsShared());
    }
    
    TSharedRef<SWidget> UMyViewportWidget::RebuildWidget()
    {
        if (IsDesignTime())
        {
            return SNew(SBox)
            .HAlign(HAlign_Center)
            .VAlign(VAlign_Center)
            [
                SNew(STextBlock).Text(NSLOCTEXT("", "", "My Viewport"))
            ];
        }
        else
        {
            ViewportWidget = SNew(SViewport);
            ViewportWidget->SetRenderDirectlyToWindow(false);
            return ViewportWidget.ToSharedRef();
        }
    }
    But I get the below crash. Attached image is the call stack.
    Code:
    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).
    Click image for larger version  Name:	Screenshot_2.png Views:	0 Size:	290.2 KB ID:	1800749
    I added the viewport widget to UMG and called InitializeViewport and above crash happens.

    Click image for larger version  Name:	Screenshot_3.png Views:	2 Size:	21.9 KB ID:	1800756
    Last edited by ryanjon2040; 08-14-2020, 03:56 AM.
    Support my RTS Game (Agora) on Patreon!
    Unreal Nexus - Create Share and Experience!
    Unreal Engine 4 World-Wide User Map

    [PLUGIN] Aws Gamelift Client Plugin
    [TOOL] Create your own binary release of UE4 from GitHub source
    My UE4 Tutorials and Misc Tools

    Lead Programmer at YetiTech Studios
    Your Friendly Neighborhood
    Satheesh PV (a.k.a RyanJon2040) | Twitter, Instagram, Facebook, LinkedIn, YouTube, Google+

    #2
    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...

    Comment


      #3
      Kassym123 I managed to put the current viewport into a UMG widget. You can find it out here: https://www.unrealengine.com/marketp...iewport-widget
      Support my RTS Game (Agora) on Patreon!
      Unreal Nexus - Create Share and Experience!
      Unreal Engine 4 World-Wide User Map

      [PLUGIN] Aws Gamelift Client Plugin
      [TOOL] Create your own binary release of UE4 from GitHub source
      My UE4 Tutorials and Misc Tools

      Lead Programmer at YetiTech Studios
      Your Friendly Neighborhood
      Satheesh PV (a.k.a RyanJon2040) | Twitter, Instagram, Facebook, LinkedIn, YouTube, Google+

      Comment

      Working...
      X