RealDocs

UKismetMathLibrary::Wrap

function Engine Blueprint Since 4.0
#include "Kismet/KismetMathLibrary.h"
Access: public Specifiers: staticBlueprintPure

Description

Wraps Value cyclically within [Min, Max], so that exceeding Max brings it back to Min and going below Min brings it to Max. Useful for cycling through indices or circular state machines.

Caveats & Gotchas

  • The range is [Min, Max] inclusive. Wrap(Max, Min, Max) returns Max, not Min — the wrap only triggers when Value steps outside the range, not when it equals the bound.
  • If Min == Max the function returns Min regardless of Value, which is correct but may hide a logic error if the equality is unintentional.

Signature

static UE_INL_API int32 Wrap(int32 Value, int32 Min, int32 Max);

Parameters

Name Type Description Default
Value int32 The value to wrap.
Min int32 Inclusive lower bound (wraps to this when exceeding Max).
Max int32 Inclusive upper bound.

Return Type

int32

Example

Cycle through weapon slots C++
int32 NumSlots = WeaponSlots.Num();
CurrentSlot = UKismetMathLibrary::Wrap(CurrentSlot + 1, 0, NumSlots - 1);

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.