UUserWidget::SetDesiredSizeInViewport
#include "Blueprint/UserWidget.h"
Access: public
Specifiers: UFUNCTIONBlueprintCallableBlueprintCosmetic
Description
Overrides the size of the widget when it is placed in the viewport via AddToViewport. Without calling this, the widget fills the entire screen.
Caveats & Gotchas
- • The size is in DPI-scaled widget units, not raw pixels. To match a pixel dimension exactly, divide by GetViewportScale.
- • Calling this before AddToViewport has no effect. The widget must be in the viewport for the size override to apply.
- • Setting this overrides the widget's own DesiredSize. If you later want the widget to auto-size again, you must set a size matching GetDesiredSize() or use a layout approach that sets size via the canvas slot instead.
Signature
UMG_API void SetDesiredSizeInViewport(FVector2D Size) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Size | FVector2D | The desired size of the widget in widget-space units. | — |
Return Type
void Example
Display a fixed-size popup over the viewport C++
PopupWidget->AddToViewport();
PopupWidget->SetDesiredSizeInViewport(FVector2D(400.f, 300.f));
PopupWidget->SetPositionInViewport(FVector2D(100.f, 100.f)); Tags
Version History
Introduced in: 4.7
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?