UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FWeakObjectPtr Struct Reference

#include <WeakObjectPtr.h>

Public Member Functions

 FWeakObjectPtr ()=default
 
UE_FORCEINLINE_HINT FWeakObjectPtr (TYPE_OF_NULLPTR)
 
UE_FORCEINLINE_HINT FWeakObjectPtr (int)
 
UE_FORCEINLINE_HINT FWeakObjectPtr (FObjectPtr Object)
 
UE_FORCEINLINE_HINT FWeakObjectPtr (const UObject *Object)
 
template<typename T >
UE_FORCEINLINE_HINT FWeakObjectPtr (TObjectPtr< T > Object)
 
 FWeakObjectPtr (const FWeakObjectPtr &Other)=default
 
void Reset ()
 
COREUOBJECT_API void operator= (FObjectPtr Object)
 
UE_FORCEINLINE_HINT void operator= (const UObject *Object)
 
template<typename T >
UE_FORCEINLINE_HINT void operator= (TObjectPtr< T > Object)
 
FWeakObjectPtroperator= (const FWeakObjectPtr &Other)=default
 
bool operator== (const FWeakObjectPtr &Other) const
 
bool operator!= (const FWeakObjectPtr &Other) const
 
bool HasSameIndexAndSerialNumber (const FWeakObjectPtr &Other) const
 
COREUOBJECT_API class UObjectGet (bool bEvenIfGarbage) const
 
COREUOBJECT_API class UObjectGet () const
 
COREUOBJECT_API class UObjectGetEvenIfUnreachable () const
 
COREUOBJECT_API class TStrongObjectPtr< UObjectPin (bool bEvenIfGarbage) const
 
COREUOBJECT_API class TStrongObjectPtr< UObjectPin () const
 
COREUOBJECT_API class TStrongObjectPtr< UObjectPinEvenIfUnreachable () const
 
COREUOBJECT_API class TStrongObjectPtr< UObjectTryPin (bool &bOutPinValid, bool bEvenIfGarbage) const
 
COREUOBJECT_API class TStrongObjectPtr< UObjectTryPin (bool &bOutPinValid) const
 
COREUOBJECT_API bool TryPinEvenIfUnreachable (class TStrongObjectPtr< UObject > &OutResult) const
 
 operator bool () const =delete
 
COREUOBJECT_API bool IsValid (bool bEvenIfGarbage, bool bThreadsafeTest=false) const
 
COREUOBJECT_API bool IsValid () const
 
COREUOBJECT_API bool IsStale (bool bIncludingGarbage=true, bool bThreadsafeTest=false) const
 
bool IsExplicitlyNull () const
 
UE_FORCEINLINE_HINT bool IsRemote () const
 
uint32 GetTypeHash () const
 
COREUOBJECT_API void Serialize (FArchive &Ar)
 

Protected Member Functions

UE_FORCEINLINE_HINT int32 GetObjectIndex () const
 

Friends

template<class , class >
struct TWeakObjectPtr
 
struct FObjectKey
 

Detailed Description

FWeakObjectPtr is a weak pointer to a UObject. It can return nullptr later if the object is garbage collected. It has no impact on if the object is garbage collected or not. It can't be directly used across a network.

Most often it is used when you explicitly do NOT want to prevent something from being garbage collected.

Constructor & Destructor Documentation

◆ FWeakObjectPtr() [1/7]

FWeakObjectPtr::FWeakObjectPtr ( )
default

◆ FWeakObjectPtr() [2/7]

UE_FORCEINLINE_HINT FWeakObjectPtr::FWeakObjectPtr ( TYPE_OF_NULLPTR  )
inline

◆ FWeakObjectPtr() [3/7]

UE_FORCEINLINE_HINT FWeakObjectPtr::FWeakObjectPtr ( int  )
inline

◆ FWeakObjectPtr() [4/7]

UE_FORCEINLINE_HINT FWeakObjectPtr::FWeakObjectPtr ( FObjectPtr  Object)
inline

Construct from an object pointer or something that can be implicitly converted to an object pointer

Parameters
Objectobject to create a weak pointer to

◆ FWeakObjectPtr() [5/7]

UE_FORCEINLINE_HINT FWeakObjectPtr::FWeakObjectPtr ( const UObject Object)
inline

◆ FWeakObjectPtr() [6/7]

template<typename T >
UE_FORCEINLINE_HINT FWeakObjectPtr::FWeakObjectPtr ( TObjectPtr< T >  Object)
inline

◆ FWeakObjectPtr() [7/7]

FWeakObjectPtr::FWeakObjectPtr ( const FWeakObjectPtr Other)
default

Construct from another weak pointer

Parameters
Otherweak pointer to copy from

Member Function Documentation

◆ Get() [1/2]

UObject * FWeakObjectPtr::Get ( ) const

Dereference the weak pointer. This is an optimized version implying bEvenIfGarbage=false.

Returns
nullptr if this object is gone or the weak pointer is explicitly null, otherwise a valid uobject pointer

◆ Get() [2/2]

UObject * FWeakObjectPtr::Get ( bool  bEvenIfGarbage) const

Dereference the weak pointer.

Parameters
bEvenIfGarbageif this is true, Garbage objects are considered valid
Returns
nullptr if this object is gone or the weak pointer is explicitly null, otherwise a valid uobject pointer

◆ GetEvenIfUnreachable()

UObject * FWeakObjectPtr::GetEvenIfUnreachable ( ) const

Dereference the weak pointer even if it is marked as Garbage or Unreachable

◆ GetObjectIndex()

UE_FORCEINLINE_HINT int32 FWeakObjectPtr::GetObjectIndex ( ) const
inlineprotected

◆ GetTypeHash()

uint32 FWeakObjectPtr::GetTypeHash ( ) const
inline

Hash function.

◆ HasSameIndexAndSerialNumber()

bool FWeakObjectPtr::HasSameIndexAndSerialNumber ( const FWeakObjectPtr Other) const
inline

Returns true if two weak pointers were originally set to the same object, even if they are now stale

Parameters
Otherweak pointer to compare to

◆ IsExplicitlyNull()

bool FWeakObjectPtr::IsExplicitlyNull ( ) const
inline

Returns true if this pointer was explicitly assigned to null, was reset, or was never initialized. If this returns true, IsValid() and IsStale() will both return false.

◆ IsRemote()

UE_FORCEINLINE_HINT bool FWeakObjectPtr::IsRemote ( ) const
inline

◆ IsStale()

bool FWeakObjectPtr::IsStale ( bool  bIncludingGarbage = true,
bool  bThreadsafeTest = false 
) const

Slightly different than !IsValid(), returns true if this used to point to a UObject, but doesn't any more and has not been assigned or reset in the mean time.

Parameters
bIncludingGarbageif this is false, Garbage objects are NOT considered stale
bThreadsafeTestset it to true when testing outside of Game Thread. Results in false if WeakObjPtr point to an existing object (no flags checked)
Returns
true if this used to point at a real object but no longer does.

◆ IsValid() [1/2]

bool FWeakObjectPtr::IsValid ( ) const

Test if this points to a live UObject. This is an optimized version implying bEvenIfGarbage=false, bThreadsafeTest=false. This should be done only when needed as excess resolution of the underlying pointer can cause performance issues. Note that IsValid can not be used on another thread as it will incorrectly return false during the mark phase of the GC due to the Unreachable flag being set. (see bThreadsafeTest above)

Returns
true if Get() would return a valid non-null pointer.

◆ IsValid() [2/2]

bool FWeakObjectPtr::IsValid ( bool  bEvenIfGarbage,
bool  bThreadsafeTest = false 
) const

Test if this points to a live UObject This should be done only when needed as excess resolution of the underlying pointer can cause performance issues.

Parameters
bEvenIfGarbageif this is true, Garbage objects are considered valid. When false, an object is considered invalid as soon as it is marked for destruction.
bThreadsafeTestif true then function will just give you information whether referenced UObject is gone forever (return false) or if it is still there (return true, no object flags checked). This is required as without it IsValid can return false during the mark phase of the GC due to the presence of the Unreachable flag.
Returns
true if Get() would return a valid non-null pointer

◆ operator bool()

FWeakObjectPtr::operator bool ( ) const
explicitdelete

◆ operator!=()

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

Compare weak pointers for inequality

Parameters
Otherweak pointer to compare to

◆ operator=() [1/4]

FWeakObjectPtr & FWeakObjectPtr::operator= ( const FWeakObjectPtr Other)
default

Construct from another weak pointer

Parameters
Otherweak pointer to copy from

◆ operator=() [2/4]

UE_FORCEINLINE_HINT void FWeakObjectPtr::operator= ( const UObject Object)
inline

◆ operator=() [3/4]

void FWeakObjectPtr::operator= ( FObjectPtr  ObjectPtr)

Copy from an object pointer

Parameters
Objectobject to create a weak pointer to

◆ operator=() [4/4]

template<typename T >
UE_FORCEINLINE_HINT void FWeakObjectPtr::operator= ( TObjectPtr< T >  Object)
inline

◆ operator==()

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

Compare weak pointers for equality. If both pointers would return nullptr from Get() they count as equal even if they were not initialized to the same object.

Parameters
Otherweak pointer to compare to

◆ Pin() [1/2]

TStrongObjectPtr< UObject > FWeakObjectPtr::Pin ( ) const

Get a strong object ptr to the weak pointer. This is an optimized version implying bEvenIfGarbage=false.

Returns
TStrongObjectPtr will be invalid if this object is gone or the weak pointer is explicitly null, otherwise a valid TStrongObjectPtr

◆ Pin() [2/2]

TStrongObjectPtr< UObject > FWeakObjectPtr::Pin ( bool  bEvenIfGarbage) const

Get a strong object ptr to the weak pointer.

Parameters
bEvenIfGarbageif this is true, Garbage objects are considered valid
Returns
TStrongObjectPtr will be invalid if this object is gone or the weak pointer is explicitly null, otherwise a valid TStrongObjectPtr

◆ PinEvenIfUnreachable()

TStrongObjectPtr< UObject > FWeakObjectPtr::PinEvenIfUnreachable ( ) const

◆ Reset()

void FWeakObjectPtr::Reset ( )
inline

Reset the weak pointer back to the null state

◆ Serialize()

void FWeakObjectPtr::Serialize ( FArchive Ar)

Weak object pointer serialization. Weak object pointers only have weak references to objects and won't serialize the object when gathering references for garbage collection. So in many cases, you don't need to bother serializing weak object pointers. However, serialization is required if you want to load and save your object.

◆ TryPin() [1/2]

class TStrongObjectPtr< UObject > FWeakObjectPtr::TryPin ( bool bOutPinValid) const

Attempt to get a strong object ptr to the weak pointer, but only if garbage collection is not in progress. This is an optimized version implying bEvenIfGarbage=false.

Parameters
bOutPinValidwill be true if the pin attempt was successful, and false if it was blocked by garbage collection
Returns
TStrongObjectPtr will be invalid if this object is gone or the weak pointer is explicitly null, otherwise a valid TStrongObjectPtr

◆ TryPin() [2/2]

class TStrongObjectPtr< UObject > FWeakObjectPtr::TryPin ( bool bOutPinValid,
bool  bEvenIfGarbage 
) const

Attempt to get a strong object ptr to the weak pointer, but only if garbage collection is not in progress.

Parameters
bEvenIfGarbageif this is true, Garbage objects are considered valid
bOutPinValidwill be true if the pin attempt was successful, and false if it was blocked by garbage collection
Returns
TStrongObjectPtr will be invalid if this object is gone or the weak pointer is explicitly null, otherwise a valid TStrongObjectPtr

◆ TryPinEvenIfUnreachable()

bool FWeakObjectPtr::TryPinEvenIfUnreachable ( class TStrongObjectPtr< UObject > &  OutResult) const

Friends And Related Symbol Documentation

◆ FObjectKey

◆ TWeakObjectPtr

template<class , class >
friend struct TWeakObjectPtr
friend

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