RealDocs

UUserWidget::AddToViewport

function UMG Blueprint Since 4.5
#include "Blueprint/UserWidget.h"
Access: public Specifiers: UFUNCTIONBlueprintCallableBlueprintCosmetic

Description

Adds this widget to the game's main viewport so it is visible on screen. The widget covers the full viewport unless sized otherwise.

Signature

void AddToViewport(int32 ZOrder = 0)

Parameters

Name Type Description Default
ZOrder int32 Z-order for layering. Higher values appear on top of lower values. 0

Return Type

void

Caveats & Gotchas

  • Calling AddToViewport on a widget that is already in the viewport is a no-op — it won't add a second copy.
  • In split-screen games, this adds the widget to the shared viewport covering all players. Use AddToPlayerScreen to restrict the widget to a single player's area.
  • Widgets added to the viewport are not automatically removed when the owning player controller is destroyed. Remove them manually in NativeDestruct or on relevant game events.
  • BlueprintCosmetic means this function is skipped on dedicated servers.

Example

Show a menu widget C++
UMyMenuWidget* Menu = CreateWidget<UMyMenuWidget>(GetWorld(), MenuClass);
Menu->AddToViewport(10);  // ZOrder 10 ensures it's above the HUD

Tags

Version History

Introduced in: 4.5

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.