FMath::GetMappedRangeValueClamped
#include "Math/UnrealMathUtility.h"
Access: public
Specifiers: static
Description
Maps a value from one range to another, clamping the input to the source range first. Equivalent to a clamped lerp between output bounds using the normalised input position.
Signature
static inline auto GetMappedRangeValueClamped(const UE::Math::TVector2<T>& InputRange, const UE::Math::TVector2<T>& OutputRange, const T2 Value) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| InputRange | FVector2D | The input range as (Min, Max). X = min, Y = max. | — |
| OutputRange | FVector2D | The output range as (Min, Max). X = min, Y = max. | — |
| Value | T | The value to map, clamped to InputRange before mapping. | — |
Return Type
T Caveats & Gotchas
- • InputRange and OutputRange are passed as FVector2D where X = min and Y = max — the naming is counterintuitive. Swapping X and Y inverts the mapping.
- • If InputRange.X == InputRange.Y (zero-width input range), the function returns OutputRange.X to avoid division by zero.
- • The output is NOT clamped to OutputRange — only the input is clamped. If the output range is wider than intended, the result can still exceed expectations if InputRange is misconfigured.
Example
Map health fraction to a material opacity C++
// Map health [0, MaxHealth] to opacity [0.2, 1.0]
float Opacity = FMath::GetMappedRangeValueClamped(
FVector2D(0.0f, MaxHealth),
FVector2D(0.2f, 1.0f),
CurrentHealth
);
Material->SetScalarParameterValue(TEXT("Opacity"), Opacity);
// Map speed [0, 600] to pitch multiplier [0.8, 1.4]
float Pitch = FMath::GetMappedRangeValueClamped(
FVector2D(0.0f, 600.0f),
FVector2D(0.8f, 1.4f),
MovementComponent->Velocity.Size()
); See Also
Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?