RealDocs

USlateBlueprintLibrary::ScreenToViewport

function UMG Blueprint Since 4.7
#include "Blueprint/SlateBlueprintLibrary.h"
Access: public Specifiers: staticUFUNCTIONBlueprintPure

Description

Converts a screen-pixel coordinate directly into UMG viewport widget space, suitable for positioning widgets added via AddToViewport at the same logical location.

Caveats & Gotchas

  • Unlike ScreenToWidgetLocal, this function has no bIncludeWindowPosition parameter — it always accounts for the window position internally. This is the correct function to use when you want to place a new UMG widget at a screen-pixel location.
  • Returns viewport-widget space, not pixel space. If you need pixel coordinates for DeprojectScreenToWorld, ScreenPosition is already in the right space — pass it directly without conversion.
  • In split-screen setups the 'viewport' is the full screen, not an individual player's sub-viewport. For split-screen per-player coordinate mapping additional logic is required.

Signature

static UMG_API void ScreenToViewport(const UObject* WorldContextObject, FVector2D ScreenPosition, FVector2D& ViewportPosition)

Parameters

Name Type Description Default
WorldContextObject const UObject* World context for viewport resolution.
ScreenPosition FVector2D Position in screen pixels.
ViewportPosition FVector2D& Output: the position in UMG viewport widget space.

Return Type

void

Example

Spawn a damage number widget at a hit screen position C++
FVector2D ViewportPos;
USlateBlueprintLibrary::ScreenToViewport(GetWorld(), HitScreenPosition, ViewportPos);
UDamageNumberWidget* Widget = CreateWidget<UDamageNumberWidget>(GetWorld());
Widget->AddToViewport();
Widget->SetPositionInViewport(ViewportPos, false);

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.