TWeakPtr

[TWeakPtr](API\Runtime\Core\Templates\TWeakPtr) is a non-intrusive reference-counted weak object pointer.

Windows
MacOS
Linux

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/Templates/SharedPointer.h

Include

#include "Templates/SharedPointer.h"

Syntax

template<class ObjectType, ESPMode Mode>
class TWeakPtr

Remarks

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.

Constructors

Name Description

Public function

TWeakPtr

NOTE: FNullTag parameter is an Unreal extension to standard shared_ptr behavior.

Public function

TWeakPtr

(
    TSharedRef< OtherType, Mode > const...
)

NOTE: The following is an Unreal extension to standard shared_ptr behavior.

Public function

TWeakPtr

(
    TSharedPtr< OtherType, Mode > const...
)

Constructs a weak pointer from a shared pointer

Public function

TWeakPtr

(
    TWeakPtr< OtherType, Mode > const&...
)

Constructs a weak pointer from a weak pointer of another type.

Public function

TWeakPtr

(
    TWeakPtr< OtherType, Mode >&& InWe...
)

Public function

TWeakPtr

(
    TWeakPtr const& InWeakPtr
)

Public function

TWeakPtr

(
    TWeakPtr&& InWeakPtr
)

Functions

Name Description

Public function Const

bool

 

HasSameObject

(
    const void* InOtherPtr
)

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

Public function Const

const bool

 

IsValid()

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

Public function Const

TSharedPtr< ...

 

Pin()

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.

Public function

void

 

Reset()

Resets this weak pointer, removing a weak reference to the object.

Operators

Name Description

Public function

TWeakPtr &

 

operator=

(
    TSharedPtr< OtherType, Mode > const...
)

Assignment operator sets this weak pointer from a shared pointer

Public function

TWeakPtr &

 

operator=

(
    TSharedRef< OtherType, Mode > const...
)

NOTE: The following is an Unreal extension to standard shared_ptr behavior.

Public function

TWeakPtr &

 

operator=

(
    TWeakPtr< OtherType, Mode > const&...
)

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

Public function

TWeakPtr &

 

operator=

(
    TWeakPtr&& InWeakPtr
)

Public function

TWeakPtr &

 

operator=

(
    TWeakPtr< OtherType, Mode >&& InWe...
)

Public function

TWeakPtr &

 

operator=

NOTE: The following is an Unreal extension to standard shared_ptr behavior.

Public function

TWeakPtr &

 

operator=

(
    TWeakPtr const& InWeakPtr
)

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

Typedefs

Name

Description

ElementType

Select Skin
Light
Dark

Welcome to the new Unreal Engine 4 Documentation site!

We're working on lots of new features including a feedback system so you can tell us how we are doing. It's not quite ready for use in the wild yet, so head over to the Documentation Feedback forum to tell us about this page or call out any issues you are encountering in the meantime.

We'll be sure to let you know when the new system is up and running.

Post Feedback