UKismetMathLibrary::Clamp
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticBlueprintPure
Description
Constrains Value to the inclusive range [Min, Max], returning Min if below and Max if above.
Caveats & Gotchas
- • If Min > Max the behaviour is undefined (implementation does Min(Max(Value, Min), Max), which returns Min). Always ensure Min <= Max; assert in debug builds if your bounds are runtime values.
- • Clamp is a clamping operation, not a wrapping operation. If you need cyclic behaviour (e.g. array indices, angles) use Wrap instead.
Signature
static UE_INL_API int32 Clamp(int32 Value, int32 Min, int32 Max); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Value | int32 | The value to constrain. | — |
| Min | int32 | Inclusive lower bound. | — |
| Max | int32 | Inclusive upper bound. | — |
Return Type
int32 Example
Clamp health to valid range C++
Health = UKismetMathLibrary::Clamp(Health + HealAmount, 0, MaxHealth); See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?