RealDocs

UKismetMathLibrary::IsNearlyZero2D

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

Description

Returns true if both components of the vector are within the given tolerance of zero. Prefer this over exact zero comparisons with floating-point vectors.

Caveats & Gotchas

  • Checks each component independently against the tolerance, not the vector's total length. A vector like (0.0001, 0.0001) passes with the default tolerance even though its length is ~0.000141.
  • The default tolerance of 1e-4 may be too loose for normalized vector comparisons — consider tightening it or using IsZero2D when only exactly-zero values are valid.

Signature

static UE_INL_API bool IsNearlyZero2D(const FVector2D& A, float Tolerance = 1.e-4f);

Parameters

Name Type Description Default
A const FVector2D& The 2D vector to check.
Tolerance float Maximum magnitude considered zero. 1.e-4f

Return Type

bool

Example

Guard against normalizing a near-zero velocity C++
FVector2D Velocity = GetCurrentVelocity2D();
if (!UKismetMathLibrary::IsNearlyZero2D(Velocity))
{
    FVector2D Dir = UKismetMathLibrary::NormalSafe2D(Velocity);
    ApplyForce(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.