RealDocs

UKismetMathLibrary::Vector4_SizeSquared

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

Description

Returns the squared Euclidean length of a FVector4 including all four components: X²+Y²+Z²+W². Avoids the square root cost of Vector4_Size.

Caveats & Gotchas

  • Like Vector4_Size, W contributes to the result. When comparing two 3D vectors stored in Vector4 with W=0, this is equivalent to squaring the 3D length — but non-zero W values will inflate the result unexpectedly.
  • When comparing distances, always compare squared values against each other rather than taking the square root first. This halves the computational cost at the expense of readability.

Signature

static UE_INL_API double Vector4_SizeSquared(const FVector4& A)

Parameters

Name Type Description Default
A const FVector4& The vector whose squared magnitude is calculated.

Return Type

double

Example

Compare two Vector4 lengths without sqrt C++
FVector4 A(3.0, 4.0, 0.0, 0.0);
FVector4 B(1.0, 1.0, 1.0, 0.0);
// Avoid sqrt — compare squared sizes directly
bool bAIsLonger = UKismetMathLibrary::Vector4_SizeSquared(A) > UKismetMathLibrary::Vector4_SizeSquared(B);
// A squared == 25, B squared == 3 — A is longer

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.