UKismetMathLibrary::ToRounded2D
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticBlueprintPure
Description
Returns a copy of the 2D vector with each component rounded to the nearest integer. Components are stored as floating-point in the returned FVector2D.
Caveats & Gotchas
- • Components are rounded using standard round-half-away-from-zero rules. FVector2D(0.5, 0.5) becomes (1, 1), not (0, 0).
- • The result is still an FVector2D (floating-point), not an integer vector type such as FIntPoint. Assign to FIntPoint explicitly if you need integer grid snapping.
Signature
static UE_INL_API FVector2D ToRounded2D(FVector2D A); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| A | FVector2D | The 2D vector whose components will be rounded. | — |
Return Type
FVector2D Example
Snap a UI position to the nearest pixel grid C++
FVector2D ScreenPos = GetMousePosition();
FVector2D Snapped = UKismetMathLibrary::ToRounded2D(ScreenPos);
SetWidgetPosition(Snapped); Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?