RealDocs

UUserWidget::AddToPlayerScreen

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

Description

Adds the widget to the player-owned screen layer rather than the global viewport. In split-screen, the widget is constrained to that player's sub-region of the viewport and does not bleed into other players' areas.

Caveats & Gotchas

  • Returns false if the widget's owning player context is not set. The widget must be created via CreateWidget passing a PlayerController (not the GameInstance) to be correctly associated with a player.
  • Unlike AddToViewport, this adds the widget to a player-specific container. Use GetPlayerScreenWidgetGeometry to get the geometry of this container for coordinate conversions.
  • Widgets added here are automatically removed when the owning PlayerController is destroyed. AddToViewport widgets persist until explicitly removed.

Signature

UMG_API bool AddToPlayerScreen(int32 ZOrder = 0)

Parameters

Name Type Description Default
ZOrder int32 Sort order within the player screen layer. Higher values appear on top. Defaults to 0. 0

Return Type

bool

Example

Add a HUD widget to a specific player's screen C++
UMyHUDWidget* HUD = CreateWidget<UMyHUDWidget>(PlayerController, UMyHUDWidget::StaticClass());
if (HUD)
{
    bool bAdded = HUD->AddToPlayerScreen();
    // bAdded is false if PlayerController context was missing
}

Version History

Introduced in: 4.7

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.