RealDocs

UKismetMathLibrary::NormalSafe2D

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

Description

Returns a unit-length copy of the 2D vector, or (0,0) if the vector is too small to normalize safely. This is the safe variant — use it in game logic to avoid division-by-zero.

Caveats & Gotchas

  • The Tolerance parameter is compared against the squared length, not the length itself. A value of 1e-8 corresponds to a length threshold of ~0.0001. Passing a linear threshold value directly will produce incorrect behavior.
  • Returns (0,0) on failure rather than asserting — callers that need to distinguish between a valid direction and no direction must check the result with IsNearlyZero2D.

Signature

static UE_INL_API FVector2D NormalSafe2D(FVector2D A, float Tolerance = 1.e-8f);

Parameters

Name Type Description Default
A FVector2D The 2D vector to normalize.
Tolerance float Minimum squared length for normalization to proceed. 1.e-8f

Return Type

FVector2D

Example

Normalize a velocity direction before applying steering C++
FVector2D Velocity = Character->GetVelocity2D();
FVector2D Dir = UKismetMathLibrary::NormalSafe2D(Velocity);
if (!Dir.IsNearlyZero())
    ApplySteering(Dir);

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.