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

#include <SharedPointer.h>

+ Inheritance diagram for TSharedFromThis< ObjectType, Mode >:

Public Member Functions

TSharedRef< ObjectType, Mode > AsShared ()
 
TSharedRef< ObjectType const, Mode > AsShared () const
 
template<typename SubobjectType >
TSharedRef< SubobjectType, Mode > AsSharedSubobject (SubobjectType *SubobjectPtr) const
 
TWeakPtr< ObjectType, Mode > AsWeak ()
 
TWeakPtr< ObjectType const, Mode > AsWeak () const
 
template<typename SubobjectType >
TWeakPtr< SubobjectType, Mode > AsWeakSubobject (SubobjectType *SubobjectPtr) const
 
template<class SharedPtrType , ESPMode SharedPtrMode, class OtherType >
void UpdateWeakReferenceInternal (TSharedPtr< SharedPtrType, SharedPtrMode > const *InSharedPtr, OtherType *InObject) const
 
template<class SharedRefType , ESPMode SharedPtrMode, class OtherType >
void UpdateWeakReferenceInternal (TSharedRef< SharedRefType, SharedPtrMode > const *InSharedRef, OtherType *InObject) const
 
UE_FORCEINLINE_HINT bool DoesSharedInstanceExist () const
 

Protected Member Functions

 TSharedFromThis ()
 
 TSharedFromThis (TSharedFromThis const &)
 
UE_FORCEINLINE_HINT TSharedFromThisoperator= (TSharedFromThis const &)
 
 ~TSharedFromThis ()
 

Static Protected Member Functions

template<class OtherType >
static UE_FORCEINLINE_HINT TSharedRef< OtherType, Mode > SharedThis (OtherType *ThisPtr)
 
template<class OtherType >
static UE_FORCEINLINE_HINT TSharedRef< OtherType const, Mode > SharedThis (const OtherType *ThisPtr)
 

Detailed Description

template<class ObjectType, ESPMode Mode>
class TSharedFromThis< ObjectType, Mode >

Derive your class from TSharedFromThis to enable access to a TSharedRef directly from an object instance that's already been allocated. Use the optional Mode template argument for thread-safety.

Constructor & Destructor Documentation

◆ TSharedFromThis() [1/2]

template<class ObjectType , ESPMode Mode>
TSharedFromThis< ObjectType, Mode >::TSharedFromThis ( )
inlineprotected

Hidden stub constructor

◆ TSharedFromThis() [2/2]

template<class ObjectType , ESPMode Mode>
TSharedFromThis< ObjectType, Mode >::TSharedFromThis ( TSharedFromThis< ObjectType, Mode > const &  )
inlineprotected

Hidden stub copy constructor

◆ ~TSharedFromThis()

template<class ObjectType , ESPMode Mode>
TSharedFromThis< ObjectType, Mode >::~TSharedFromThis ( )
inlineprotected

Hidden destructor

Member Function Documentation

◆ AsShared() [1/2]

template<class ObjectType , ESPMode Mode>
TSharedRef< ObjectType, Mode > TSharedFromThis< ObjectType, Mode >::AsShared ( )
inline

Provides a shared reference to this object. Note that is only valid to call this after a shared reference (or shared pointer) to the object has already been created. Also note that it is illegal to call this in the object's destructor.

Returns
Returns this object as a shared reference

◆ AsShared() [2/2]

template<class ObjectType , ESPMode Mode>
TSharedRef< ObjectType const, Mode > TSharedFromThis< ObjectType, Mode >::AsShared ( ) const
inline

Provides a shared reference to this object (const.) Note that is only valid to call this after a shared reference (or shared pointer) to the object has already been created. Also note that it is illegal to call this in the object's destructor.

Returns
Returns this object as a shared reference (const)

◆ AsSharedSubobject()

template<class ObjectType , ESPMode Mode>
template<typename SubobjectType >
TSharedRef< SubobjectType, Mode > TSharedFromThis< ObjectType, Mode >::AsSharedSubobject ( SubobjectType SubobjectPtr) const
inline

Provides a shared reference to a subobject of this object, i.e. points to an object which shares the lifetime and refcount of this object, but isn't derived from TSharedFromThis. Note that is only valid to call this after a shared reference (or shared pointer) to the object has already been created. Also note that it is illegal to call this in the object's destructor.

Returns
Returns the subobject as a shared reference.

◆ AsWeak() [1/2]

template<class ObjectType , ESPMode Mode>
TWeakPtr< ObjectType, Mode > TSharedFromThis< ObjectType, Mode >::AsWeak ( )
inline

Provides a weak reference to this object. Note that is only valid to call this after a shared reference (or shared pointer) to the object has already been created. Also note that it is illegal to call this in the object's destructor.

Returns
Returns this object as a weak pointer

◆ AsWeak() [2/2]

template<class ObjectType , ESPMode Mode>
TWeakPtr< ObjectType const, Mode > TSharedFromThis< ObjectType, Mode >::AsWeak ( ) const
inline

◆ AsWeakSubobject()

template<class ObjectType , ESPMode Mode>
template<typename SubobjectType >
TWeakPtr< SubobjectType, Mode > TSharedFromThis< ObjectType, Mode >::AsWeakSubobject ( SubobjectType SubobjectPtr) const
inline

Provides a weak pointer to a subobject of this object, i.e. points to an object which shares the lifetime and refcount of this object, but isn't derived from TSharedFromThis. Note that is only valid to call this after a shared reference (or shared pointer) to the object has already been created. Also note that it is illegal to call this in the object's destructor.

Returns
Returns the subobject as a weak pointer.

◆ DoesSharedInstanceExist()

template<class ObjectType , ESPMode Mode>
UE_FORCEINLINE_HINT bool TSharedFromThis< ObjectType, Mode >::DoesSharedInstanceExist ( ) const
inline

Checks whether our referenced instance is valid (ie, whether it's safe to call AsShared). If this returns false, it means that your instance has either:

  • Not yet been assigned to a shared pointer (via MakeShared or MakeShareable).
  • Is currently within its constructor (so the shared instance isn't yet available).
  • Is currently within its destructor (so the shared instance is no longer available).

◆ operator=()

template<class ObjectType , ESPMode Mode>
UE_FORCEINLINE_HINT TSharedFromThis & TSharedFromThis< ObjectType, Mode >::operator= ( TSharedFromThis< ObjectType, Mode > const &  )
inlineprotected

Hidden stub assignment operator

◆ SharedThis() [1/2]

template<class ObjectType , ESPMode Mode>
template<class OtherType >
static UE_FORCEINLINE_HINT TSharedRef< OtherType const, Mode > TSharedFromThis< ObjectType, Mode >::SharedThis ( const OtherType ThisPtr)
inlinestaticprotected

Provides access to a shared reference to an object, given the object's 'this' pointer. Uses the 'this' pointer to derive the object's actual type, then casts and returns an appropriately typed shared reference. Intentionally declared 'protected', as should only be called when the 'this' pointer can be passed.

Returns
Returns this object as a shared pointer (const)

◆ SharedThis() [2/2]

template<class ObjectType , ESPMode Mode>
template<class OtherType >
static UE_FORCEINLINE_HINT TSharedRef< OtherType, Mode > TSharedFromThis< ObjectType, Mode >::SharedThis ( OtherType ThisPtr)
inlinestaticprotected

Provides access to a shared reference to an object, given the object's 'this' pointer. Uses the 'this' pointer to derive the object's actual type, then casts and returns an appropriately typed shared reference. Intentionally declared 'protected', as should only be called when the 'this' pointer can be passed.

Returns
Returns this object as a shared pointer

◆ UpdateWeakReferenceInternal() [1/2]

template<class ObjectType , ESPMode Mode>
template<class SharedPtrType , ESPMode SharedPtrMode, class OtherType >
void TSharedFromThis< ObjectType, Mode >::UpdateWeakReferenceInternal ( TSharedPtr< SharedPtrType, SharedPtrMode > const *  InSharedPtr,
OtherType InObject 
) const
inline

INTERNAL USE ONLY – Do not call this method. Freshens the internal weak pointer object using the supplied object pointer along with the authoritative shared reference to the object. Note that until this function is called, calls to AsShared() will result in an empty pointer.

◆ UpdateWeakReferenceInternal() [2/2]

template<class ObjectType , ESPMode Mode>
template<class SharedRefType , ESPMode SharedPtrMode, class OtherType >
void TSharedFromThis< ObjectType, Mode >::UpdateWeakReferenceInternal ( TSharedRef< SharedRefType, SharedPtrMode > const *  InSharedRef,
OtherType InObject 
) const
inline

INTERNAL USE ONLY – Do not call this method. Freshens the internal weak pointer object using the supplied object pointer along with the authoritative shared reference to the object. Note that until this function is called, calls to AsShared() will result in an empty pointer.


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