UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TWeakObjectPtr< T, TWeakObjectPtrBase > Struct Template Reference

#include <WeakObjectPtrTemplates.h>

Public Types

using ElementType = T
 

Public Member Functions

 TWeakObjectPtr ()=default
 
 TWeakObjectPtr (const TWeakObjectPtr &)=default
 
TWeakObjectPtroperator= (const TWeakObjectPtr &)=default
 
 ~TWeakObjectPtr ()=default
 
FORCEINLINE TWeakObjectPtr (TYPE_OF_NULLPTR)
 
template<typename U >
FORCEINLINE TWeakObjectPtr (U Object)
 
template<typename OtherT >
FORCEINLINE TWeakObjectPtr (const TWeakObjectPtr< OtherT, TWeakObjectPtrBase > &Other)
 
FORCEINLINE void Reset ()
 
template<typename U >
FORCEINLINE TWeakObjectPtroperator= (U *Object)
 
template<typename OtherT >
FORCEINLINE TWeakObjectPtroperator= (const TWeakObjectPtr< OtherT, TWeakObjectPtrBase > &Other)
 
FORCEINLINE T * Get (bool bEvenIfPendingKill) const
 
FORCEINLINE T * Get () const
 
FORCEINLINE TStrongObjectPtr< T > Pin (bool bEvenIfPendingKill) const
 
FORCEINLINE TStrongObjectPtr< T > Pin () const
 
FORCEINLINE TStrongObjectPtr< T > TryPin (bool &bOutPinValid, bool bEvenIfPendingKill) const
 
FORCEINLINE TStrongObjectPtr< T > TryPin (bool &bOutPinValid) const
 
FORCEINLINE T * GetEvenIfUnreachable () const
 
FORCEINLINE T & operator* () const
 
FORCEINLINE T * operator-> () const
 
 operator bool () const =delete
 
 operator TWeakObjectPtrBase () const
 
FORCEINLINE bool IsValid (bool bEvenIfPendingKill, bool bThreadsafeTest=false) const
 
FORCEINLINE bool IsValid () const
 
FORCEINLINE bool IsStale (bool bIncludingIfPendingKill=true, bool bThreadsafeTest=false) const
 
FORCEINLINE bool IsExplicitlyNull () const
 
FORCEINLINE bool HasSameIndexAndSerialNumber (const TWeakObjectPtr &Other) const
 
template<typename OtherT UE_REQUIRES>
FORCEINLINE bool HasSameIndexAndSerialNumber (const TWeakObjectPtr< OtherT, TWeakObjectPtrBase > &Other) const
 
FORCEINLINE bool IsRemote () const
 
FORCEINLINE void Serialize (FArchive &Ar)
 
FORCEINLINE uint32 GetWeakPtrTypeHash () const
 
template<typename RhsT , typename = decltype((T*)nullptr == (RhsT*)nullptr)>
FORCENOINLINE bool UEOpEquals (const TWeakObjectPtr< RhsT, TWeakObjectPtrBase > &Rhs) const
 
template<typename RhsT , typename = decltype((T*)nullptr == (RhsT*)nullptr)>
FORCENOINLINE bool UEOpEquals (const RhsT *Rhs) const
 
FORCENOINLINE bool UEOpEquals (TYPE_OF_NULLPTR) const
 
template<typename RhsT , typename = decltype((T*)nullptr != (RhsT*)nullptr)>
FORCEINLINE bool operator!= (const TWeakObjectPtr< RhsT, TWeakObjectPtrBase > &Rhs) const
 
template<typename RhsT , typename = decltype((T*)nullptr != (RhsT*)nullptr)>
FORCEINLINE bool operator!= (const RhsT *Rhs) const
 
FORCEINLINE bool operator!= (TYPE_OF_NULLPTR) const
 

Friends

struct FFieldPath
 
template<class , class >
struct TWeakObjectPtr
 

Detailed Description

template<class T, class TWeakObjectPtrBase>
struct TWeakObjectPtr< T, TWeakObjectPtrBase >

TWeakObjectPtr is the templated version of the generic FWeakObjectPtr

Examples
/work/Engine/Source/Runtime/UMG/Public/Components/Widget.h.

Member Typedef Documentation

◆ ElementType

template<class T , class TWeakObjectPtrBase >
using TWeakObjectPtr< T, TWeakObjectPtrBase >::ElementType = T

Constructor & Destructor Documentation

◆ TWeakObjectPtr() [1/5]

template<class T , class TWeakObjectPtrBase >
TWeakObjectPtr< T, TWeakObjectPtrBase >::TWeakObjectPtr ( )
default

◆ TWeakObjectPtr() [2/5]

template<class T , class TWeakObjectPtrBase >
TWeakObjectPtr< T, TWeakObjectPtrBase >::TWeakObjectPtr ( const TWeakObjectPtr< T, TWeakObjectPtrBase > &  )
default

◆ ~TWeakObjectPtr()

template<class T , class TWeakObjectPtrBase >
TWeakObjectPtr< T, TWeakObjectPtrBase >::~TWeakObjectPtr ( )
default

◆ TWeakObjectPtr() [3/5]

Construct from a null pointer

◆ TWeakObjectPtr() [4/5]

template<class T , class TWeakObjectPtrBase >
template<typename U >
FORCEINLINE TWeakObjectPtr< T, TWeakObjectPtrBase >::TWeakObjectPtr ( Object)
inline

Construct from an object pointer

Parameters
Objectobject to create a weak pointer to

◆ TWeakObjectPtr() [5/5]

Construct from another weak pointer of another type, intended for derived-to-base conversions

Parameters
Otherweak pointer to copy from

Member Function Documentation

◆ Get() [1/2]

template<class T , class TWeakObjectPtrBase >
FORCEINLINE T * TWeakObjectPtr< T, TWeakObjectPtrBase >::Get ( ) const
inline

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

◆ Get() [2/2]

template<class T , class TWeakObjectPtrBase >
FORCEINLINE T * TWeakObjectPtr< T, TWeakObjectPtrBase >::Get ( bool  bEvenIfPendingKill) const
inline

Dereference the weak pointer

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

◆ GetEvenIfUnreachable()

template<class T , class TWeakObjectPtrBase >
FORCEINLINE T * TWeakObjectPtr< T, TWeakObjectPtrBase >::GetEvenIfUnreachable ( ) const
inline

Deferences the weak pointer even if its marked RF_Unreachable. This is needed to resolve weak pointers during GC (such as AddReferenceObjects)

◆ GetWeakPtrTypeHash()

template<class T , class TWeakObjectPtrBase >
FORCEINLINE uint32 TWeakObjectPtr< T, TWeakObjectPtrBase >::GetWeakPtrTypeHash ( ) const
inline

Hash function.

◆ HasSameIndexAndSerialNumber() [1/2]

template<class T , class TWeakObjectPtrBase >
FORCEINLINE bool TWeakObjectPtr< T, TWeakObjectPtrBase >::HasSameIndexAndSerialNumber ( const TWeakObjectPtr< T, TWeakObjectPtrBase > &  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

◆ HasSameIndexAndSerialNumber() [2/2]

template<class T , class TWeakObjectPtrBase >
template<typename OtherT UE_REQUIRES>
FORCEINLINE bool TWeakObjectPtr< T, TWeakObjectPtrBase >::HasSameIndexAndSerialNumber ( const TWeakObjectPtr< OtherT, TWeakObjectPtrBase > &  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()

template<class T , class TWeakObjectPtrBase >
FORCEINLINE bool TWeakObjectPtr< T, TWeakObjectPtrBase >::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()

template<class T , class TWeakObjectPtrBase >
FORCEINLINE bool TWeakObjectPtr< T, TWeakObjectPtrBase >::IsRemote ( ) const
inline

◆ IsStale()

template<class T , class TWeakObjectPtrBase >
FORCEINLINE bool TWeakObjectPtr< T, TWeakObjectPtrBase >::IsStale ( bool  bIncludingIfPendingKill = true,
bool  bThreadsafeTest = false 
) const
inline

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
bIncludingIfPendingKillif this is true, pendingkill objects are 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]

template<class T , class TWeakObjectPtrBase >
FORCEINLINE bool TWeakObjectPtr< T, TWeakObjectPtrBase >::IsValid ( ) const
inline

Test if this points to a live UObject. This is an optimized version implying bEvenIfPendingKill=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]

template<class T , class TWeakObjectPtrBase >
FORCEINLINE bool TWeakObjectPtr< T, TWeakObjectPtrBase >::IsValid ( bool  bEvenIfPendingKill,
bool  bThreadsafeTest = false 
) const
inline

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
bEvenIfPendingKillif this is true, pendingkill objects are considered valid
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()

template<class T , class TWeakObjectPtrBase >
TWeakObjectPtr< T, TWeakObjectPtrBase >::operator bool ( ) const
explicitdelete

◆ operator TWeakObjectPtrBase()

template<class T , class TWeakObjectPtrBase >
TWeakObjectPtr< T, TWeakObjectPtrBase >::operator TWeakObjectPtrBase ( ) const
inlineexplicit

Cast to the underlying generic FWeakObjectPtr type

◆ operator!=() [1/3]

template<class T , class TWeakObjectPtrBase >
template<typename RhsT , typename = decltype((T*)nullptr != (RhsT*)nullptr)>
FORCEINLINE bool TWeakObjectPtr< T, TWeakObjectPtrBase >::operator!= ( const RhsT Rhs) const
inline

◆ operator!=() [2/3]

template<class T , class TWeakObjectPtrBase >
template<typename RhsT , typename = decltype((T*)nullptr != (RhsT*)nullptr)>
FORCEINLINE bool TWeakObjectPtr< T, TWeakObjectPtrBase >::operator!= ( const TWeakObjectPtr< RhsT, TWeakObjectPtrBase > &  Rhs) const
inline

Compare weak pointers for inequality

Parameters
Otherweak pointer to compare to

◆ operator!=() [3/3]

◆ operator*()

template<class T , class TWeakObjectPtrBase >
FORCEINLINE T & TWeakObjectPtr< T, TWeakObjectPtrBase >::operator* ( ) const
inline

Dereference the weak pointer

◆ operator->()

template<class T , class TWeakObjectPtrBase >
FORCEINLINE T * TWeakObjectPtr< T, TWeakObjectPtrBase >::operator-> ( ) const
inline

Dereference the weak pointer

◆ operator=() [1/3]

template<class T , class TWeakObjectPtrBase >
TWeakObjectPtr & TWeakObjectPtr< T, TWeakObjectPtrBase >::operator= ( const TWeakObjectPtr< T, TWeakObjectPtrBase > &  )
default

◆ operator=() [2/3]

template<class T , class TWeakObjectPtrBase >
template<typename OtherT >
FORCEINLINE TWeakObjectPtr & TWeakObjectPtr< T, TWeakObjectPtrBase >::operator= ( const TWeakObjectPtr< OtherT, TWeakObjectPtrBase > &  Other)
inline

Assign from another weak pointer, intended for derived-to-base conversions

Parameters
Otherweak pointer to copy from

◆ operator=() [3/3]

template<class T , class TWeakObjectPtrBase >
template<typename U >
FORCEINLINE TWeakObjectPtr & TWeakObjectPtr< T, TWeakObjectPtrBase >::operator= ( U *  Object)
inline

Copy from an object pointer

Parameters
Objectobject to create a weak pointer to

◆ Pin() [1/2]

template<class T , class TWeakObjectPtrBase >
FORCEINLINE TStrongObjectPtr< T > TWeakObjectPtr< T, TWeakObjectPtrBase >::Pin ( ) const
inline

Pin the weak pointer as a strong ptr. This is an optimized version implying bEvenIfPendingKill=false.

◆ Pin() [2/2]

template<class T , class TWeakObjectPtrBase >
FORCEINLINE TStrongObjectPtr< T > TWeakObjectPtr< T, TWeakObjectPtrBase >::Pin ( bool  bEvenIfPendingKill) const
inline

Pin the weak pointer and get a strongptr.

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

◆ Reset()

template<class T , class TWeakObjectPtrBase >
FORCEINLINE void TWeakObjectPtr< T, TWeakObjectPtrBase >::Reset ( )
inline

Reset the weak pointer back to the null state

◆ Serialize()

template<class T , class TWeakObjectPtrBase >
FORCEINLINE void TWeakObjectPtr< T, TWeakObjectPtrBase >::Serialize ( FArchive Ar)
inline

Weak object pointer serialization, this forwards to FArchive::operator<<(struct FWeakObjectPtr&) or an override

◆ TryPin() [1/2]

template<class T , class TWeakObjectPtrBase >
FORCEINLINE TStrongObjectPtr< T > TWeakObjectPtr< T, TWeakObjectPtrBase >::TryPin ( bool bOutPinValid) const
inline

Pin the weak pointer as a strong ptr. This is an optimized version implying bEvenIfPendingKill=false.

◆ TryPin() [2/2]

template<class T , class TWeakObjectPtrBase >
FORCEINLINE TStrongObjectPtr< T > TWeakObjectPtr< T, TWeakObjectPtrBase >::TryPin ( bool bOutPinValid,
bool  bEvenIfPendingKill 
) const
inline

Pin the weak pointer and get a strongptr.

Parameters
bOutPinValidtrue if garbage collection was not in progress, and OutResult was successfully captured, false if garbage collection was in progress and OutResult was not captured
bEvenIfPendingKillif this is true, pendingkill objects are considered valid
Returns
nullptr if this object is gone or the weak pointer is explicitly null, otherwise a valid uobject pointer

◆ UEOpEquals() [1/3]

template<class T , class TWeakObjectPtrBase >
template<typename RhsT , typename = decltype((T*)nullptr == (RhsT*)nullptr)>
FORCENOINLINE bool TWeakObjectPtr< T, TWeakObjectPtrBase >::UEOpEquals ( const RhsT Rhs) const
inline

◆ UEOpEquals() [2/3]

template<class T , class TWeakObjectPtrBase >
template<typename RhsT , typename = decltype((T*)nullptr == (RhsT*)nullptr)>
FORCENOINLINE bool TWeakObjectPtr< T, TWeakObjectPtrBase >::UEOpEquals ( const TWeakObjectPtr< RhsT, TWeakObjectPtrBase > &  Rhs) 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

◆ UEOpEquals() [3/3]

template<class T , class TWeakObjectPtrBase >
FORCENOINLINE bool TWeakObjectPtr< T, TWeakObjectPtrBase >::UEOpEquals ( TYPE_OF_NULLPTR  ) const
inline

Friends And Related Symbol Documentation

◆ FFieldPath

template<class T , class TWeakObjectPtrBase >
FFieldPath
friend

◆ TWeakObjectPtr

template<class T , class TWeakObjectPtrBase >
template<class , class >
friend struct TWeakObjectPtr
friend

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