UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TWeakPtr< ObjectType, InMode > Class Template Reference

#include <SharedPointer.h>

Public Types

using ElementType = ObjectType
 
using IntrusiveUnsetOptionalStateType = TWeakPtr
 

Public Member Functions

 TWeakPtr (SharedPointerInternals::FNullTag *=nullptr)
 
template<typename OtherType >
 TWeakPtr (TSharedRef< OtherType, Mode > const &InSharedRef)
 
template<typename OtherType >
 TWeakPtr (TSharedPtr< OtherType, Mode > const &InSharedPtr)
 
template<typename OtherType >
 TWeakPtr (TWeakPtr< OtherType, Mode > const &InWeakPtr, SharedPointerInternals::FStaticCastTag)
 
template<typename OtherType >
 TWeakPtr (TWeakPtr< OtherType, Mode > const &InWeakPtr, SharedPointerInternals::FConstCastTag)
 
template<typename OtherType >
 TWeakPtr (TWeakPtr< OtherType, Mode > const &InWeakPtr)
 
template<typename OtherType >
 TWeakPtr (TWeakPtr< OtherType, Mode > &&InWeakPtr)
 
 TWeakPtr (TWeakPtr const &InWeakPtr)
 
 TWeakPtr (TWeakPtr &&InWeakPtr)
 
TWeakPtroperator= (SharedPointerInternals::FNullTag *)
 
TWeakPtroperator= (TWeakPtr const &InWeakPtr)
 
TWeakPtroperator= (TWeakPtr &&InWeakPtr)
 
template<typename OtherType >
TWeakPtroperator= (TWeakPtr< OtherType, Mode > const &InWeakPtr)
 
template<typename OtherType >
TWeakPtroperator= (TWeakPtr< OtherType, Mode > &&InWeakPtr)
 
template<typename OtherType >
TWeakPtroperator= (TSharedRef< OtherType, Mode > const &InSharedRef)
 
template<typename OtherType >
TWeakPtroperator= (TSharedPtr< OtherType, Mode > const &InSharedPtr)
 
UE_FORCEINLINE_HINT TSharedPtr< ObjectType, ModePin () const &
 
UE_FORCEINLINE_HINT TSharedPtr< ObjectType, ModePin () &&
 
UE_FORCEINLINE_HINT bool IsValid () const
 
UE_FORCEINLINE_HINT void Reset ()
 
UE_FORCEINLINE_HINT bool HasSameObject (const void *InOtherPtr) const
 
UE_FORCEINLINE_HINT uint32 GetWeakPtrTypeHash () const
 
 TWeakPtr (FIntrusiveUnsetOptionalState)
 
bool UEOpEquals (FIntrusiveUnsetOptionalState) const
 
template<typename OtherType >
bool UEOpEquals (const TWeakPtr< OtherType, Mode > &Rhs) const
 
UE_REWRITE bool UEOpEquals (TYPE_OF_NULLPTR) const
 
template<typename OtherType >
bool UEOpLessThan (const TWeakPtr< OtherType, Mode > &Rhs) const
 

Static Public Attributes

static constexpr ESPMode Mode = InMode
 
static constexpr bool bHasIntrusiveUnsetOptionalState = true
 

Friends

template<class OtherType , ESPMode OtherMode>
class TWeakPtr
 
template<class OtherType , ESPMode OtherMode>
class TSharedPtr
 

Detailed Description

template<class ObjectType, ESPMode InMode>
class TWeakPtr< ObjectType, InMode >

TWeakPtr is a non-intrusive reference-counted weak object pointer. This weak pointer will be conditionally thread-safe when the optional Mode template argument is set to ThreadSafe.

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

Member Typedef Documentation

◆ ElementType

template<class ObjectType , ESPMode InMode>
using TWeakPtr< ObjectType, InMode >::ElementType = ObjectType

◆ IntrusiveUnsetOptionalStateType

template<class ObjectType , ESPMode InMode>
using TWeakPtr< ObjectType, InMode >::IntrusiveUnsetOptionalStateType = TWeakPtr

Constructor & Destructor Documentation

◆ TWeakPtr() [1/10]

template<class ObjectType , ESPMode InMode>
TWeakPtr< ObjectType, InMode >::TWeakPtr ( SharedPointerInternals::FNullTag = nullptr)
inline

Constructs an empty TWeakPtr

◆ TWeakPtr() [2/10]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TWeakPtr< ObjectType, InMode >::TWeakPtr ( TSharedRef< OtherType, Mode > const &  InSharedRef)
inline

Constructs a weak pointer from a shared reference

Parameters
InSharedRefThe shared reference to create a weak pointer from

◆ TWeakPtr() [3/10]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TWeakPtr< ObjectType, InMode >::TWeakPtr ( TSharedPtr< OtherType, Mode > const &  InSharedPtr)
inline

Constructs a weak pointer from a shared pointer

Parameters
InSharedPtrThe shared pointer to create a weak pointer from

◆ TWeakPtr() [4/10]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TWeakPtr< ObjectType, InMode >::TWeakPtr ( TWeakPtr< OtherType, Mode > const &  InWeakPtr,
SharedPointerInternals::FStaticCastTag   
)
inline

Special constructor used internally to statically cast one weak pointer type to another. You should never call this constructor directly. Instead, use the StaticCastWeakPtr() function. This constructor creates a weak pointer as a weak reference to an existing weak pointer after statically casting that pointer's object. This constructor is needed for static casts.

Parameters
InWeakPtrThe weak pointer whose object we should create an additional reference to

◆ TWeakPtr() [5/10]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TWeakPtr< ObjectType, InMode >::TWeakPtr ( TWeakPtr< OtherType, Mode > const &  InWeakPtr,
SharedPointerInternals::FConstCastTag   
)
inline

Special constructor used internally to cast a 'const' weak pointer a 'mutable' pointer. You should never call this constructor directly. Instead, use the ConstCastWeakPtr() function. This constructor creates a weak pointer as a weak reference to an existing weak pointer after const casting that pointer's object. This constructor is needed for const casts.

Parameters
InWeakPtrThe weak pointer whose object we should create an additional reference to

◆ TWeakPtr() [6/10]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TWeakPtr< ObjectType, InMode >::TWeakPtr ( TWeakPtr< OtherType, Mode > const &  InWeakPtr)
inline

Constructs a weak pointer from a weak pointer of another type. This constructor is intended to allow derived-to-base conversions.

Parameters
InWeakPtrThe weak pointer to create a weak pointer from

◆ TWeakPtr() [7/10]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TWeakPtr< ObjectType, InMode >::TWeakPtr ( TWeakPtr< OtherType, Mode > &&  InWeakPtr)
inline

◆ TWeakPtr() [8/10]

template<class ObjectType , ESPMode InMode>
TWeakPtr< ObjectType, InMode >::TWeakPtr ( TWeakPtr< ObjectType, InMode > const &  InWeakPtr)
inline

◆ TWeakPtr() [9/10]

template<class ObjectType , ESPMode InMode>
TWeakPtr< ObjectType, InMode >::TWeakPtr ( TWeakPtr< ObjectType, InMode > &&  InWeakPtr)
inline

◆ TWeakPtr() [10/10]

template<class ObjectType , ESPMode InMode>
TWeakPtr< ObjectType, InMode >::TWeakPtr ( FIntrusiveUnsetOptionalState  )
inlineexplicit

Member Function Documentation

◆ GetWeakPtrTypeHash()

template<class ObjectType , ESPMode InMode>
UE_FORCEINLINE_HINT uint32 TWeakPtr< ObjectType, InMode >::GetWeakPtrTypeHash ( ) const
inline

◆ HasSameObject()

template<class ObjectType , ESPMode InMode>
UE_FORCEINLINE_HINT bool TWeakPtr< ObjectType, InMode >::HasSameObject ( const void InOtherPtr) const
inline

Returns true if the object this weak pointer points to is the same as the specified object pointer.

◆ IsValid()

template<class ObjectType , ESPMode InMode>
UE_FORCEINLINE_HINT bool TWeakPtr< ObjectType, InMode >::IsValid ( ) const
inline

Checks to see if this weak pointer actually has a valid reference to an object

Returns
True if the weak pointer is valid and a pin operator would have succeeded

◆ operator=() [1/7]

template<class ObjectType , ESPMode InMode>
TWeakPtr & TWeakPtr< ObjectType, InMode >::operator= ( SharedPointerInternals::FNullTag )
inline

Assignment to a nullptr pointer. Clears this weak pointer's reference.

◆ operator=() [2/7]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TWeakPtr & TWeakPtr< ObjectType, InMode >::operator= ( TSharedPtr< OtherType, Mode > const &  InSharedPtr)
inline

Assignment operator sets this weak pointer from a shared pointer

Parameters
InSharedPtrThe shared pointer used to assign to this weak pointer

◆ operator=() [3/7]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TWeakPtr & TWeakPtr< ObjectType, InMode >::operator= ( TSharedRef< OtherType, Mode > const &  InSharedRef)
inline

Assignment operator sets this weak pointer from a shared reference

Parameters
InSharedRefThe shared reference used to assign to this weak pointer

◆ operator=() [4/7]

template<class ObjectType , ESPMode InMode>
TWeakPtr & TWeakPtr< ObjectType, InMode >::operator= ( TWeakPtr< ObjectType, InMode > &&  InWeakPtr)
inline

◆ operator=() [5/7]

template<class ObjectType , ESPMode InMode>
TWeakPtr & TWeakPtr< ObjectType, InMode >::operator= ( TWeakPtr< ObjectType, InMode > const &  InWeakPtr)
inline

Assignment operator adds a weak reference to the object referenced by the specified weak pointer

Parameters
InWeakPtrThe weak pointer for the object to assign

◆ operator=() [6/7]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TWeakPtr & TWeakPtr< ObjectType, InMode >::operator= ( TWeakPtr< OtherType, Mode > &&  InWeakPtr)
inline

◆ operator=() [7/7]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TWeakPtr & TWeakPtr< ObjectType, InMode >::operator= ( TWeakPtr< OtherType, Mode > const &  InWeakPtr)
inline

Assignment operator adds a weak reference to the object referenced by the specified weak pointer. This assignment operator is intended to allow derived-to-base conversions.

Parameters
InWeakPtrThe weak pointer for the object to assign

◆ Pin() [1/2]

template<class ObjectType , ESPMode InMode>
UE_FORCEINLINE_HINT TSharedPtr< ObjectType, Mode > TWeakPtr< ObjectType, InMode >::Pin ( ) &&
inline

Converts this weak pointer to a shared pointer that you can use to access the object (if it hasn't expired yet.) Remember, if there are no more shared references to the object, the returned shared pointer will not be valid. You should always check to make sure the returned pointer is valid before trying to dereference the shared pointer!

Returns
Shared pointer for this object (will only be valid if still referenced!)

◆ Pin() [2/2]

template<class ObjectType , ESPMode InMode>
UE_FORCEINLINE_HINT TSharedPtr< ObjectType, Mode > TWeakPtr< ObjectType, InMode >::Pin ( ) const &
inline

Converts this weak pointer to a shared pointer that you can use to access the object (if it hasn't expired yet.) Remember, if there are no more shared references to the object, the returned shared pointer will not be valid. You should always check to make sure the returned pointer is valid before trying to dereference the shared pointer!

Returns
Shared pointer for this object (will only be valid if still referenced!)

◆ Reset()

template<class ObjectType , ESPMode InMode>
UE_FORCEINLINE_HINT void TWeakPtr< ObjectType, InMode >::Reset ( )
inline

Resets this weak pointer, removing a weak reference to the object. If there are no other shared or weak references to the object, then the tracking object will be destroyed.

◆ UEOpEquals() [1/3]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
bool TWeakPtr< ObjectType, InMode >::UEOpEquals ( const TWeakPtr< OtherType, Mode > &  Rhs) const
inline

◆ UEOpEquals() [2/3]

template<class ObjectType , ESPMode InMode>
bool TWeakPtr< ObjectType, InMode >::UEOpEquals ( FIntrusiveUnsetOptionalState  ) const
inline

◆ UEOpEquals() [3/3]

template<class ObjectType , ESPMode InMode>
UE_REWRITE bool TWeakPtr< ObjectType, InMode >::UEOpEquals ( TYPE_OF_NULLPTR  ) const
inline

◆ UEOpLessThan()

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
bool TWeakPtr< ObjectType, InMode >::UEOpLessThan ( const TWeakPtr< OtherType, Mode > &  Rhs) const
inline

Friends And Related Symbol Documentation

◆ TSharedPtr

template<class ObjectType , ESPMode InMode>
template<class OtherType , ESPMode OtherMode>
friend class TSharedPtr
friend

◆ TWeakPtr

template<class ObjectType , ESPMode InMode>
template<class OtherType , ESPMode OtherMode>
friend class TWeakPtr
friend

Member Data Documentation

◆ bHasIntrusiveUnsetOptionalState

template<class ObjectType , ESPMode InMode>
constexpr bool TWeakPtr< ObjectType, InMode >::bHasIntrusiveUnsetOptionalState = true
staticconstexpr

◆ Mode

template<class ObjectType , ESPMode InMode>
constexpr ESPMode TWeakPtr< ObjectType, InMode >::Mode = InMode
staticconstexpr

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