CommonUI How to push a widget and not have the previous widget disappear?

I have a “Exit Game?” Yes/No widget that works nicely in game. But I’d like to reuse it on the main menu. The problem is that the main menu disappears when the ExitGame widget is pushed onto the widget stack. How do I keep the main screen visible?

I thought it might be “Deactivated Visibility” setting on the main menu, but that does nothing.

Any help?

1 Like

I created my own stack from a UObject and just added the widget to the viewport using a different ZOrder like this. Works great. Wish there was an easier way, but it’s not too bad.

#pragma once

#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "CommonActivatableWidget.h"
#include "UIStack.generated.h"

UCLASS(BlueprintType)
class TOWERDEFENSE_API UUIStack : public UObject
{
	GENERATED_BODY()
	
  UPROPERTY()
  TArray<TObjectPtr<UCommonActivatableWidget>> Stack;

  UFUNCTION(BlueprintCallable)
  void PushWidget(UCommonActivatableWidget *Widget);

  UFUNCTION(BlueprintCallable)
  void PopWidget();
};
#include "UIStack.h"

void UUIStack::PushWidget(UCommonActivatableWidget* Widget)
{
  if (!Stack.IsEmpty())
  {
    Stack[Stack.Num()-1]->DeactivateWidget();
  }
  Stack.Add(Widget);
  Widget->AddToViewport(Stack.Num());
  Widget->ActivateWidget();
}

void UUIStack::PopWidget()
{
  if (!Stack.IsEmpty())
  {
    UCommonActivatableWidget* Widget = Stack[Stack.Num()-1];
    Widget->DeactivateWidget();
    Widget->RemoveFromParent();
    Stack.RemoveAt(Stack.Num()-1);
  }
  if (!Stack.IsEmpty())
  {
    UCommonActivatableWidget* Widget = Stack[Stack.Num() - 1];
    Widget->ActivateWidget();
  }
}

So you have to create the widget yourself and then add it.

So you just need to create the stack somewhere that’s accessible and call PushWidget and PopWidget. I have a global GameActor blueprint that accissible from anywhere.

Leaving this here in case someone else needs it.

I’m now looking to see if there’s a way to blur the background while a popup is on screen.

Yeah, there’s a background blur widget. So just make a new widget with a container slot in the blur widget, then you can manually add that in and put the popup widget in the slot in the code above.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.