RealDocs

UKismetMathLibrary::GridSnap_Float

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

Description

Snaps a float value to the nearest multiple of GridSize. For example, Location=5.1 and GridSize=10.0 returns 10.0.

Caveats & Gotchas

  • If GridSize is 0, Location is returned unchanged — no divide-by-zero error, but the snap silently does nothing. Guard against GridSize == 0 if it's user-supplied.
  • Precision issues can occur when GridSize is very small (e.g., 0.001) due to floating-point representation — the snap target may not be the exact integer multiple you expect.

Signature

static UE_INL_API double GridSnap_Float(double Location, double GridSize);

Parameters

Name Type Description Default
Location double The value to snap.
GridSize double The grid interval to snap to.

Return Type

double

Example

Snap a placement position to a 100 UU grid C++
FVector RawHit = HitResult.Location;
FVector Snapped;
Snapped.X = UKismetMathLibrary::GridSnap_Float(RawHit.X, 100.0);
Snapped.Y = UKismetMathLibrary::GridSnap_Float(RawHit.Y, 100.0);
Snapped.Z = RawHit.Z;
SetActorLocation(Snapped);

Tags

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.