RealDocs

UKismetMathLibrary::Vector_SnappedToGrid

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

Description

Snaps each component of a vector to the nearest multiple of InGridSize. Useful for grid-based placement, voxel systems, or rounding world positions to tile boundaries.

Caveats & Gotchas

  • InGridSize must be non-zero. Passing 0 causes a division-by-zero and produces NaN in each component. Guard with a non-zero check if the grid size is a user-configurable value.
  • Snapping is done independently per axis using the same grid size for all three. If you need different step sizes per axis (e.g. snapping XY to a tile grid but Z to floor levels), apply FMath::GridSnap manually per component.

Signature

static UE_INL_API FVector Vector_SnappedToGrid(FVector InVect, float InGridSize);

Parameters

Name Type Description Default
InVect FVector The vector to snap.
InGridSize float The grid step size. Each component is rounded to the nearest multiple of this value.

Return Type

FVector

Example

Snap a placement ghost to a 100-unit grid C++
FVector CursorWorldPos = GetCursorWorldPosition();
FVector SnappedPos = UKismetMathLibrary::Vector_SnappedToGrid(CursorWorldPos, 100.f);
GhostActor->SetActorLocation(SnappedPos);

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.