UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FVariant Class Reference

#include <Variant.h>

Public Member Functions

 FVariant ()
 
 FVariant (const FVariant &)=default
 
FVariantoperator= (const FVariant &)=default
 
 ~FVariant ()=default
 
 FVariant (FVariant &&Other)
 
FVariantoperator= (FVariant &&Other)
 
template<typename T >
 FVariant (T InValue)
 
 FVariant (TArray< uint8 > &&InArray)
 
 FVariant (const TArray< uint8 > &InArray)
 
 FVariant (const TCHAR *InString)
 
template<typename T >
FVariantoperator= (T InValue)
 
FVariantoperator= (TArray< uint8 > &&InArray)
 
FVariantoperator= (const TArray< uint8 > &InArray)
 
FVariantoperator= (const TCHAR *InString)
 
template<typename T >
 operator T () const
 
bool operator== (const FVariant &Other) const
 
bool operator!= (const FVariant &Other) const
 
void Empty ()
 
bool IsEmpty () const
 
const TArray< uint8 > & GetBytes () const
 
int32 GetSize () const
 
EVariantTypes GetType () const
 
template<typename T >
GetValue () const
 
template<>
TArray< uint8GetValue () const
 

Friends

FArchiveoperator<< (FArchive &Ar, FVariant &Variant)
 

Detailed Description

Implements an extensible union of multiple types.

Variant types can be used to store a range of different built-in types, as well as user defined types. The values are internally serialized into a byte array, which means that only FArchive serializable types are supported at this time.

Constructor & Destructor Documentation

◆ FVariant() [1/7]

FVariant::FVariant ( )
inline

Default constructor.

◆ FVariant() [2/7]

FVariant::FVariant ( const FVariant )
default

◆ ~FVariant()

FVariant::~FVariant ( )
default

◆ FVariant() [3/7]

FVariant::FVariant ( FVariant &&  Other)
inline

◆ FVariant() [4/7]

template<typename T >
FVariant::FVariant ( InValue)
inline

Creates and initializes a new instance with the specified value.

Parameters
InValueThe initial value.

◆ FVariant() [5/7]

FVariant::FVariant ( TArray< uint8 > &&  InArray)
inline

Creates and initializes a new instance from a byte array.

Array values are passed straight through as an optimization. Please note that, if you serialize any complex types into arrays and then store them in FVariant, you will be responsible for ensuring byte ordering if the FVariant gets sent over the network.

Parameters
InValue-The initial value.

◆ FVariant() [6/7]

FVariant::FVariant ( const TArray< uint8 > &  InArray)
inline

◆ FVariant() [7/7]

FVariant::FVariant ( const TCHAR InString)
inline

Creates and initializes a new instance from a TCHAR string.

Parameters
InStringThe initial value.

Member Function Documentation

◆ Empty()

void FVariant::Empty ( )
inline

Empties the value.

See also
IsEmpty

◆ GetBytes()

const TArray< uint8 > & FVariant::GetBytes ( ) const
inline

Gets the stored value as a byte array.

This method returns the internal representation of any value as an array of raw bytes. To retrieve values of type TArray<uint8> use GetValue<TArray<uint8>>() instead.

Returns
Byte array.
See also
GetValue

◆ GetSize()

int32 FVariant::GetSize ( ) const
inline

Gets the stored value's size (in bytes).

Returns
Size of the value.
See also
GetType, GetValue

◆ GetType()

EVariantTypes FVariant::GetType ( ) const
inline

Gets the stored value's type.

Returns
Type of the value.
See also
GetSize, GetValue

◆ GetValue() [1/2]

template<>
TArray< uint8 > FVariant::GetValue ( ) const
inline

Gets the stored value for byte arrays.

Array values are passed straight through as an optimization. Please note that, if you serialize any complex types into arrays and then store them in FVariant, you will be responsible for ensuring byte ordering if the FVariant gets send over the network.

To retrieve any value as an array of serialized bytes, use GetBytes() instead.

Returns
The byte array.
See also
GetBytes

◆ GetValue() [2/2]

template<typename T >
T FVariant::GetValue ( ) const
inline

Gets the stored value.

This template function does not provide any automatic conversion between convertible types. The exact type of the value to be extracted must be known.

Returns
The value.
See also
GetSize, GetType

◆ IsEmpty()

bool FVariant::IsEmpty ( ) const
inline

Checks whether the value is empty.

Returns
true if the value is empty, false otherwise.
See also
Empty

◆ operator T()

template<typename T >
FVariant::operator T ( ) const
inline

Implicit conversion operator.

Parameters
TThe type to convert the value to.
Returns
The value converted to the specified type.

◆ operator!=()

bool FVariant::operator!= ( const FVariant Other) const
inline

Comparison operator for inequality.

Parameters
OtherThe variant to compare with.
Returns
true if the values are not equal, false otherwise.

◆ operator=() [1/6]

FVariant & FVariant::operator= ( const FVariant )
default

◆ operator=() [2/6]

FVariant & FVariant::operator= ( const TArray< uint8 > &  InArray)
inline

◆ operator=() [3/6]

FVariant & FVariant::operator= ( const TCHAR InString)
inline

Assignment operator for TCHAR strings.

Parameters
InStringThe value to assign.
Returns
This instance.

◆ operator=() [4/6]

FVariant & FVariant::operator= ( FVariant &&  Other)
inline

◆ operator=() [5/6]

template<typename T >
FVariant & FVariant::operator= ( InValue)
inline

Assignment operator.

Parameters
TThe type of the value to assign.
InValueThe value to assign.
Returns
This instance.

◆ operator=() [6/6]

FVariant & FVariant::operator= ( TArray< uint8 > &&  InArray)
inline

Assignment operator for byte arrays.

Array values are passed straight through as an optimization. Please note that, if you serialize any complex types into arrays and then store them in FVariant, you will be responsible for ensuring byte ordering if the FVariant gets sent over the network.

Parameters
InArrayThe byte array to assign.
Returns
This instance.

◆ operator==()

bool FVariant::operator== ( const FVariant Other) const
inline

Comparison operator for equality.

Parameters
OtherThe variant to compare with.
Returns
true if the values are equal, false otherwise.

Friends And Related Symbol Documentation

◆ operator<<

FArchive & operator<< ( FArchive Ar,
FVariant Variant 
)
friend

Serializes the given variant type from or into the specified archive.

Parameters
ArThe archive to serialize from or into.
VariantThe value to serialize.
Returns
The archive.

The documentation for this class was generated from the following file: