UWidgetLayoutLibrary::GetViewportWidgetGeometry
#include "Blueprint/WidgetLayoutLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintCallable
Description
Returns the FGeometry of the root viewport widget — the container that holds all widgets added via AddToViewport. Use this geometry to convert between absolute and local coordinate spaces for viewport-level widgets.
Caveats & Gotchas
- • Returns a default-constructed FGeometry if no viewport exists yet (before the viewport has been painted at least once). Check IsValid() on the world before calling.
- • This is the geometry for the *viewport* container, not for any individual widget. Use UWidget::GetCachedGeometry for a specific widget's geometry.
- • Combine with USlateBlueprintLibrary conversion functions to translate mouse or world positions into viewport-local coordinates.
Signature
static UMG_API FGeometry GetViewportWidgetGeometry(const UObject* WorldContextObject) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | const UObject* | Any UObject that provides world context. | — |
Return Type
FGeometry Example
Convert absolute mouse position to viewport local space C++
FGeometry ViewportGeo = UWidgetLayoutLibrary::GetViewportWidgetGeometry(this);
FVector2D AbsoluteMousePos; // from platform or input event
FVector2D LocalMousePos = USlateBlueprintLibrary::AbsoluteToLocal(ViewportGeo, AbsoluteMousePos); See Also
Tags
Version History
Introduced in: 4.17
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?