UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
UE::Math::TVector4< T > Struct Template Reference

#include <Vector4.h>

Public Types

using FReal = T
 

Public Member Functions

 TVector4 (const UE::Math::TVector< T > &InVector)
 
template<typename FArg UE_REQUIRES>
 TVector4 (const UE::Math::TVector< T > &InVector, FArg InW)
 
template<typename FArg UE_REQUIRES>
 TVector4 (const UE::Math::TVector4< T > &InVector, FArg OverrideW)
 
 TVector4 (const FLinearColor &InColor)
 
 TVector4 (const FLinearColor &InColor, T InOverrideW)
 
 TVector4 (T InX=0.0f, T InY=0.0f, T InZ=0.0f, T InW=1.0f)
 
 TVector4 (TVector2< T > InXY, TVector2< T > InZW)
 
template<typename IntType >
 TVector4 (const TIntVector4< IntType > &InVector)
 
 TVector4 (EForceInit)
 
 TVector4 (ENoInit)
 
UE_FORCEINLINE_HINT T & operator[] (int32 ComponentIndex)
 
UE_FORCEINLINE_HINToperator[] (int32 ComponentIndex) const
 
UE_FORCEINLINE_HINT TVector4< T > operator- () const
 
UE_FORCEINLINE_HINT TVector4< T > operator+ (const TVector4< T > &V) const
 
TVector4< T > operator+= (const TVector4< T > &V)
 
UE_FORCEINLINE_HINT TVector4< T > operator- (const TVector4< T > &V) const
 
TVector4< T > operator-= (const TVector4< T > &V)
 
template<typename FArg UE_REQUIRES>
UE_FORCEINLINE_HINT TVector4< T > operator+ (FArg Bias) const
 
template<typename FArg UE_REQUIRES>
UE_FORCEINLINE_HINT TVector4< T > operator- (FArg Bias) const
 
template<typename FArg UE_REQUIRES>
UE_FORCEINLINE_HINT TVector4< T > operator* (FArg Scale) const
 
template<typename FArg UE_REQUIRES>
TVector4< T > operator/ (FArg Scale) const
 
TVector4< T > operator/ (const TVector4< T > &V) const
 
TVector4< T > operator* (const TVector4< T > &V) const
 
TVector4< T > operator*= (const TVector4< T > &V)
 
TVector4< T > operator/= (const TVector4< T > &V)
 
template<typename FArg UE_REQUIRES>
TVector4< T > operator*= (FArg Scale)
 
template<typename FArg UE_REQUIRES>
TVector4< T > operator/= (FArg Scale)
 
bool operator== (const TVector4< T > &V) const
 
bool operator!= (const TVector4< T > &V) const
 
TVector4< T > operator^ (const TVector4< T > &V) const
 
T & Component (int32 Index)
 
const T & Component (int32 Index) const
 
bool IsValidIndex (int32 Index) const
 
bool Equals (const TVector4< T > &V, T Tolerance=UE_KINDA_SMALL_NUMBER) const
 
bool IsUnit3 (T LengthSquaredTolerance=UE_KINDA_SMALL_NUMBER) const
 
FString ToString () const
 
bool InitFromString (const FString &InSourceString)
 
TVector4 GetSafeNormal (T Tolerance=UE_SMALL_NUMBER) const
 
TVector4 GetUnsafeNormal3 () const
 
CORE_API TRotator< T > ToOrientationRotator () const
 
CORE_API TQuat< T > ToOrientationQuat () const
 
UE_FORCEINLINE_HINT TRotator< T > Rotation () const
 
void Set (T InX, T InY, T InZ, T InW)
 
TVector4< T > ComponentMin (const TVector4< T > &Other) const
 
TVector4< T > ComponentMax (const TVector4< T > &Other) const
 
Size3 () const
 
SizeSquared3 () const
 
Size () const
 
SizeSquared () const
 
bool ContainsNaN () const
 
bool IsNearlyZero3 (T Tolerance=UE_KINDA_SMALL_NUMBER) const
 
bool IsNearlyZero (T Tolerance=UE_KINDA_SMALL_NUMBER) const
 
TVector4< T > Reflect3 (const TVector4< T > &Normal) const
 
void FindBestAxisVectors3 (TVector4< T > &Axis1, TVector4< T > &Axis2) const
 
UE_FORCEINLINE_HINT void DiagnosticCheckNaN ()
 
bool Serialize (FArchive &Ar)
 
bool SerializeFromMismatchedTag (FName StructTag, FArchive &Ar)
 
template<typename FArg UE_REQUIRES>
 TVector4 (const TVector4< FArg > &From)
 
template<typename FArg UE_REQUIRES>
 TVector4 (const TVector4< FArg > &From)
 
template<typename IntType >
UE_FORCEINLINE_HINT TVector4 (const TIntVector4< IntType > &InVector)
 

Static Public Member Functions

static TVector4< T > Zero ()
 
static TVector4< T > One ()
 

Public Attributes

union { 
 
   struct { 
 
      T   X 
 
      T   Y 
 
      T   Z 
 
      T   W 
 
   }  
 
   T   XYZW [4] 
 
};  
 

Static Public Attributes

static CORE_API constexpr int32 NumComponents = 4
 

Friends

UE_FORCEINLINE_HINT friend uint32 GetTypeHash (const UE::Math::TVector4< T > &Vector)
 

Detailed Description

template<typename T>
struct UE::Math::TVector4< T >

A 4D homogeneous vector, 4x1 FLOATs, 16-byte aligned.

Member Typedef Documentation

◆ FReal

template<typename T >
using UE::Math::TVector4< T >::FReal = T

Constructor & Destructor Documentation

◆ TVector4() [1/13]

template<typename T >
UE::Math::TVector4< T >::TVector4 ( const UE::Math::TVector< T > &  InVector)
inline

Constructor from 3D TVector. W is set to 1.

Parameters
InVector3D Vector to set first three components.

◆ TVector4() [2/13]

template<typename T >
template<typename FArg UE_REQUIRES>
UE::Math::TVector4< T >::TVector4 ( const UE::Math::TVector< T > &  InVector,
FArg  InW 
)
inline

Constructor.

Parameters
InVector3D Vector to set first three components.
InWW Coordinate.

◆ TVector4() [3/13]

template<typename T >
template<typename FArg UE_REQUIRES>
UE::Math::TVector4< T >::TVector4 ( const UE::Math::TVector4< T > &  InVector,
FArg  OverrideW 
)
inline

Constructor allowing copying of an TVector4 whilst setting up a new W component.

Parameters
InVector4D Vector to set first three components.
InOverrideWReplaces W Coordinate of InVector.

◆ TVector4() [4/13]

template<typename T >
UE::Math::TVector4< T >::TVector4 ( const FLinearColor InColor)
inline

Creates and initializes a new vector from a color value.

Parameters
InColourColor used to set vector.

◆ TVector4() [5/13]

template<typename T >
UE::Math::TVector4< T >::TVector4 ( const FLinearColor InColor,
InOverrideW 
)
inline

Creates and initializes a new vector from a color RGB and W

Parameters
InColourColor used to set XYZ.
InOverrideW

◆ TVector4() [6/13]

template<typename T >
UE::Math::TVector4< T >::TVector4 ( InX = 0.0f,
InY = 0.0f,
InZ = 0.0f,
InW = 1.0f 
)
inlineexplicit

Creates and initializes a new vector from the specified components.

Parameters
InXX Coordinate.
InYY Coordinate.
InZZ Coordinate.
InWW Coordinate.

NOTE: This default constructor is unlike TVector, TMatrix etc. in that it actually initializes the instance. Ideally it should be = default; in the same way, but this would break backwards compatibility.

◆ TVector4() [7/13]

template<typename T >
UE::Math::TVector4< T >::TVector4 ( TVector2< T >  InXY,
TVector2< T >  InZW 
)
inlineexplicit

Creates and initializes a new vector from the specified 2D vectors.

Parameters
InXYA 2D vector holding the X- and Y-components.
InZWA 2D vector holding the Z- and W-components.

◆ TVector4() [8/13]

template<typename T >
template<typename IntType >
UE::Math::TVector4< T >::TVector4 ( const TIntVector4< IntType > &  InVector)

Creates and initializes a new vector from an int vector value.

Parameters
InVectorIntVector used to set vector.

◆ TVector4() [9/13]

template<typename T >
UE::Math::TVector4< T >::TVector4 ( EForceInit  )
inlineexplicit

Creates and initializes a new vector to zero.

Parameters
EForceInitForce Init Enum.

◆ TVector4() [10/13]

template<typename T >
UE_FORCEINLINE_HINT UE::Math::TVector4< T >::TVector4 ( ENoInit  )

Creates an uninitialized new vector.

Parameters
ENoInitForce uninitialized enum.

◆ TVector4() [11/13]

template<typename T >
template<typename FArg UE_REQUIRES>
UE::Math::TVector4< T >::TVector4 ( const TVector4< FArg > &  From)
inlineexplicit

◆ TVector4() [12/13]

template<typename T >
template<typename FArg UE_REQUIRES>
UE::Math::TVector4< T >::TVector4 ( const TVector4< FArg > &  From)
inlineexplicit

◆ TVector4() [13/13]

template<typename T >
template<typename IntType >
UE_FORCEINLINE_HINT UE::Math::TVector4< T >::TVector4 ( const TIntVector4< IntType > &  InVector)

Member Function Documentation

◆ Component() [1/2]

template<typename T >
T & UE::Math::TVector4< T >::Component ( int32  Index)
inline

Gets a specific component of the vector.

Parameters
IndexThe index of the component.
Returns
Reference to the component.

◆ Component() [2/2]

template<typename T >
const T & UE::Math::TVector4< T >::Component ( int32  Index) const
inline

Gets a specific component of the vector.

Parameters
IndexThe index of the component.
Returns
Reference to the component.

◆ ComponentMax()

template<typename T >
UE_FORCEINLINE_HINT TVector4< T > UE::Math::TVector4< T >::ComponentMax ( const TVector4< T > &  Other) const

Gets the component-wise max of two vectors.

◆ ComponentMin()

template<typename T >
UE_FORCEINLINE_HINT TVector4< T > UE::Math::TVector4< T >::ComponentMin ( const TVector4< T > &  Other) const

Gets the component-wise min of two vectors.

◆ ContainsNaN()

template<typename T >
bool UE::Math::TVector4< T >::ContainsNaN ( ) const
inline

Utility to check if there are any non-finite values (NaN or Inf) in this vector.

◆ DiagnosticCheckNaN()

template<typename T >
UE_FORCEINLINE_HINT void UE::Math::TVector4< T >::DiagnosticCheckNaN ( )
inline

◆ Equals()

template<typename T >
UE_FORCEINLINE_HINT bool UE::Math::TVector4< T >::Equals ( const TVector4< T > &  V,
Tolerance = UE_KINDA_SMALL_NUMBER 
) const

Error tolerant comparison.

Parameters
VVector to compare against.
ToleranceError Tolerance.
Returns
true if the two vectors are equal within specified tolerance, otherwise false.

◆ FindBestAxisVectors3()

template<typename T >
void UE::Math::TVector4< T >::FindBestAxisVectors3 ( TVector4< T > &  Axis1,
TVector4< T > &  Axis2 
) const
inline

Find good arbitrary axis vectors to represent U and V axes of a plane, given just the normal.

◆ GetSafeNormal()

template<typename T >
TVector4< T > UE::Math::TVector4< T >::GetSafeNormal ( Tolerance = UE_SMALL_NUMBER) const
inline

Returns a normalized copy of the vector if safe to normalize.

Parameters
ToleranceMinimum squared length of vector for normalization.
Returns
A normalized copy of the vector or a zero vector.

◆ GetUnsafeNormal3()

template<typename T >
TVector4< T > UE::Math::TVector4< T >::GetUnsafeNormal3 ( ) const
inline

Calculates normalized version of vector without checking if it is non-zero.

Returns
Normalized version of vector.

◆ InitFromString()

template<typename T >
bool UE::Math::TVector4< T >::InitFromString ( const FString &  InSourceString)
inline

Initialize this Vector based on an FString. The String is expected to contain X=, Y=, Z=, W=. The TVector4 will be bogus when InitFromString returns false.

Parameters
InSourceStringFString containing the vector values.
Returns
true if the X,Y,Z values were read successfully; false otherwise.

◆ IsNearlyZero()

template<typename T >
bool UE::Math::TVector4< T >::IsNearlyZero ( Tolerance = UE_KINDA_SMALL_NUMBER) const
inline

Utility to check if all of the components of this vector are nearly zero given the tolerance.

◆ IsNearlyZero3()

template<typename T >
bool UE::Math::TVector4< T >::IsNearlyZero3 ( Tolerance = UE_KINDA_SMALL_NUMBER) const
inline

Utility to check if the XYZ components of this vector are nearly zero given the tolerance.

◆ IsUnit3()

template<typename T >
UE_FORCEINLINE_HINT bool UE::Math::TVector4< T >::IsUnit3 ( LengthSquaredTolerance = UE_KINDA_SMALL_NUMBER) const

Check if the vector is of unit length, with specified tolerance.

Parameters
LengthSquaredToleranceTolerance against squared length.
Returns
true if the vector is a unit vector within the specified tolerance.

◆ IsValidIndex()

template<typename T >
bool UE::Math::TVector4< T >::IsValidIndex ( int32  Index) const

Tests if index is valid, i.e. greater than or equal to zero, and less than the number of components in the vector.

Parameters
IndexIndex to test.
Returns
True if index is valid. False otherwise.

◆ One()

template<typename T >
static TVector4< T > UE::Math::TVector4< T >::One ( )
inlinestatic

◆ operator!=()

template<typename T >
UE_FORCEINLINE_HINT bool UE::Math::TVector4< T >::operator!= ( const TVector4< T > &  V) const

Checks for inequality against another vector.

Parameters
VThe other vector.
Returns
true if the two vectors are different, otherwise false.

◆ operator*() [1/2]

template<typename T >
UE_FORCEINLINE_HINT TVector4< T > UE::Math::TVector4< T >::operator* ( const TVector4< T > &  V) const

Gets the result of multiplying a vector with this.

Parameters
VThe vector to multiply.
Returns
The result of vector multiplication.

◆ operator*() [2/2]

template<typename T >
template<typename FArg UE_REQUIRES>
UE_FORCEINLINE_HINT TVector4< T > UE::Math::TVector4< T >::operator* ( FArg  Scale) const
inline

Gets the result of scaling this vector.

Parameters
ScaleThe scaling factor.
Returns
The result of vector scaling.

◆ operator*=() [1/2]

template<typename T >
TVector4< T > UE::Math::TVector4< T >::operator*= ( const TVector4< T > &  V)
inline

Gets the result of multiplying a vector with another Vector (component wise).

Parameters
VThe vector to multiply.
Returns
The result of vector multiplication.

◆ operator*=() [2/2]

template<typename T >
template<typename FArg UE_REQUIRES>
TVector4< T > UE::Math::TVector4< T >::operator*= ( FArg  Scale)
inline

Gets the result of scaling this vector.

Parameters
ScaleThe scaling factor.
Returns
The result of vector scaling.

◆ operator+() [1/2]

template<typename T >
UE_FORCEINLINE_HINT TVector4< T > UE::Math::TVector4< T >::operator+ ( const TVector4< T > &  V) const

Gets the result of adding a vector to this.

Parameters
VThe vector to add.
Returns
The result of vector addition.

◆ operator+() [2/2]

template<typename T >
template<typename FArg UE_REQUIRES>
UE_FORCEINLINE_HINT TVector4< T > UE::Math::TVector4< T >::operator+ ( FArg  Bias) const
inline

Gets the result of adding to each component of the vector.

Parameters
BiasHow much to add to each component.
Returns
The result of addition.

◆ operator+=()

template<typename T >
TVector4< T > UE::Math::TVector4< T >::operator+= ( const TVector4< T > &  V)
inline

Adds another vector to this one.

Parameters
VThe other vector to add.
Returns
Copy of the vector after addition.

◆ operator-() [1/3]

template<typename T >
UE_FORCEINLINE_HINT TVector4< T > UE::Math::TVector4< T >::operator- ( ) const

Gets a negated copy of the vector.

Returns
A negated copy of the vector.

◆ operator-() [2/3]

template<typename T >
UE_FORCEINLINE_HINT TVector4< T > UE::Math::TVector4< T >::operator- ( const TVector4< T > &  V) const

Gets the result of subtracting a vector from this.

Parameters
VThe vector to subtract.
Returns
The result of vector subtraction.

◆ operator-() [3/3]

template<typename T >
template<typename FArg UE_REQUIRES>
UE_FORCEINLINE_HINT TVector4< T > UE::Math::TVector4< T >::operator- ( FArg  Bias) const
inline

Gets the result of subtracting from each component of the vector.

Parameters
BiasHow much to subtract from each component.
Returns
The result of subtraction.

◆ operator-=()

template<typename T >
TVector4< T > UE::Math::TVector4< T >::operator-= ( const TVector4< T > &  V)
inline

Subtracts another vector to this one.

Parameters
VThe other vector to subtract.
Returns
Copy of the vector after subtraction.

◆ operator/() [1/2]

template<typename T >
UE_FORCEINLINE_HINT TVector4< T > UE::Math::TVector4< T >::operator/ ( const TVector4< T > &  V) const

Gets the result of dividing this vector.

Parameters
VWhat to divide by.
Returns
The result of division.

◆ operator/() [2/2]

template<typename T >
template<typename FArg UE_REQUIRES>
TVector4< T > UE::Math::TVector4< T >::operator/ ( FArg  Scale) const
inline

Gets the result of dividing this vector.

Parameters
ScaleWhat to divide by.
Returns
The result of division.

◆ operator/=() [1/2]

template<typename T >
TVector4< T > UE::Math::TVector4< T >::operator/= ( const TVector4< T > &  V)
inline

Gets the result of dividing a vector with another Vector (component wise).

Parameters
VThe vector to divide with.
Returns
The result of vector multiplication.

◆ operator/=() [2/2]

template<typename T >
template<typename FArg UE_REQUIRES>
TVector4< T > UE::Math::TVector4< T >::operator/= ( FArg  Scale)
inline

Gets the result of scaling this vector by 1/Scale.

Parameters
ScaleThe inverse scaling factor.
Returns
The result of vector scaling by 1/Scale.

◆ operator==()

template<typename T >
UE_FORCEINLINE_HINT bool UE::Math::TVector4< T >::operator== ( const TVector4< T > &  V) const

Checks for equality against another vector.

Parameters
VThe other vector.
Returns
true if the two vectors are the same, otherwise false.

◆ operator[]() [1/2]

template<typename T >
UE_FORCEINLINE_HINT T & UE::Math::TVector4< T >::operator[] ( int32  ComponentIndex)

Access a specific component of the vector.

Parameters
ComponentIndexThe index of the component.
Returns
Reference to the desired component.

◆ operator[]() [2/2]

template<typename T >
UE_FORCEINLINE_HINT T UE::Math::TVector4< T >::operator[] ( int32  ComponentIndex) const

Access a specific component of the vector.

Parameters
ComponentIndexThe index of the component.
Returns
Copy of the desired component.

◆ operator^()

template<typename T >
TVector4< T > UE::Math::TVector4< T >::operator^ ( const TVector4< T > &  V) const
inline

Calculate Cross product between this and another vector.

Parameters
VThe other vector.
Returns
The Cross product.

◆ Reflect3()

template<typename T >
UE_FORCEINLINE_HINT TVector4< T > UE::Math::TVector4< T >::Reflect3 ( const TVector4< T > &  Normal) const

Reflect vector.

◆ Rotation()

template<typename T >
UE_FORCEINLINE_HINT TRotator< T > UE::Math::TVector4< T >::Rotation ( ) const
inline

Return the FRotator orientation corresponding to the direction in which the vector points. Sets Yaw and Pitch to the proper numbers, and sets roll to zero because the roll can't be determined from a vector. Identical to 'ToOrientationRotator()'.

Returns
FRotator from the Vector's direction.
See also
ToOrientationRotator()

◆ Serialize()

template<typename T >
bool UE::Math::TVector4< T >::Serialize ( FArchive Ar)
inline

◆ SerializeFromMismatchedTag()

template<typename T >
bool UE::Math::TVector4< T >::SerializeFromMismatchedTag ( FName  StructTag,
FArchive Ar 
)
inline

◆ Set()

template<typename T >
void UE::Math::TVector4< T >::Set ( InX,
InY,
InZ,
InW 
)
inline

Set all of the vectors coordinates.

Parameters
InXNew X Coordinate.
InYNew Y Coordinate.
InZNew Z Coordinate.
InWNew W Coordinate.

◆ Size()

template<typename T >
UE_FORCEINLINE_HINT T UE::Math::TVector4< T >::Size ( ) const

Get the length (magnitude) of this vector, taking the W component into account

Returns
The length of this vector

◆ Size3()

template<typename T >
UE_FORCEINLINE_HINT T UE::Math::TVector4< T >::Size3 ( ) const

Get the length of this vector not taking W component into account.

Returns
The length of this vector.

◆ SizeSquared()

template<typename T >
UE_FORCEINLINE_HINT T UE::Math::TVector4< T >::SizeSquared ( ) const

Get the squared length of this vector, taking the W component into account

Returns
The squared length of this vector

◆ SizeSquared3()

template<typename T >
UE_FORCEINLINE_HINT T UE::Math::TVector4< T >::SizeSquared3 ( ) const

Get the squared length of this vector not taking W component into account.

Returns
The squared length of this vector.

◆ ToOrientationQuat()

template<typename T >
UE::Math::TQuat< T > UE::Math::TVector4< T >::ToOrientationQuat ( ) const

Return the Quaternion orientation corresponding to the direction in which the vector points.

Returns
Quaternion from the Vector's direction.

◆ ToOrientationRotator()

template<typename T >
UE::Math::TRotator< T > UE::Math::TVector4< T >::ToOrientationRotator ( ) const

Return the FRotator orientation corresponding to the direction in which the vector points. Sets Yaw and Pitch to the proper numbers, and sets roll to zero because the roll can't be determined from a vector.

Returns
FRotator from the Vector's direction.

◆ ToString()

template<typename T >
UE_FORCEINLINE_HINT FString UE::Math::TVector4< T >::ToString ( ) const

Get a textual representation of the vector.

Returns
Text describing the vector.

◆ Zero()

template<typename T >
static TVector4< T > UE::Math::TVector4< T >::Zero ( )
inlinestatic

Friends And Related Symbol Documentation

◆ GetTypeHash

template<typename T >
UE_FORCEINLINE_HINT friend uint32 GetTypeHash ( const UE::Math::TVector4< T > &  Vector)
friend

Creates a hash value from a TVector4.

Parameters
Vectorthe vector to create a hash value for
Returns
The hash value from the components

Member Data Documentation

◆ [union]

union { ... } UE::Math::TVector4< T >

◆ NumComponents

template<typename T >
CORE_API constexpr int32 UE::Math::TVector4< T >::NumComponents = 4
staticconstexpr

The number of components this vector type has.

◆ W

template<typename T >
T UE::Math::TVector4< T >::W

The vector's W-component.

◆ X

template<typename T >
T UE::Math::TVector4< T >::X

The vector's X-component.

◆ XYZW

template<typename T >
T UE::Math::TVector4< T >::XYZW[4]

◆ Y

template<typename T >
T UE::Math::TVector4< T >::Y

The vector's Y-component.

◆ Z

template<typename T >
T UE::Math::TVector4< T >::Z

The vector's Z-component.


The documentation for this struct was generated from the following files: