UKismetMathLibrary::ClampAxes2D
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPure
Description
Returns a copy of the vector with both X and Y clamped to [MinAxisVal, MaxAxisVal]. Use this to keep a 2D coordinate within a valid screen or texture region.
Caveats & Gotchas
- • Both axes use the same min/max range. If you need different clamp ranges per axis, clamp X and Y separately using FMath::Clamp.
- • Passing MinAxisVal > MaxAxisVal produces undefined behaviour — the underlying FMath::Clamp does not validate the range.
Signature
static UE_INL_API FVector2D ClampAxes2D(FVector2D A, double MinAxisVal, double MaxAxisVal); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| A | FVector2D | The vector whose axes will be clamped. | — |
| MinAxisVal | double | Minimum allowed value for both X and Y. | — |
| MaxAxisVal | double | Maximum allowed value for both X and Y. | — |
Return Type
FVector2D Example
Constrain a cursor position to a bounding box C++
FVector2D CursorPos(1500.f, -20.f);
FVector2D Clamped = UKismetMathLibrary::ClampAxes2D(CursorPos, 0.0, 1280.0);
// Clamped = (1280, 0) Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?