FWeakObjectPtr

[FWeakObjectPtr](API\Runtime\CoreUObject\UObject\FWeakObjectPtr) is a weak pointer to a [UObject](API\Runtime\CoreUObject\UObject\UObject).

Windows
MacOS
Linux

References

Module

CoreUObject

Header

/Engine/Source/Runtime/CoreUObject/Public/UObject/WeakObjectPtr.h

Include

#include "UObject/WeakObjectPtr.h"

Syntax

struct FWeakObjectPtr

Remarks

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.

Constructors

Name Description

Public function

FWeakObjectPtr()

Null constructor

Public function

FWeakObjectPtr

(
    const UObject* Object
)

Construct from an object pointer

Public function

FWeakObjectPtr

(
    const FWeakObjectPtr& Other
)

Construct from another weak pointer

Functions

Name Description

Public function Const

UObject *...

 

Get

(
    bool bEvenIfPendingKill
)

Dereference the weak pointer.

Public function Const

UObject *...

 

Get()

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

Public function Const

UObject *...

 

GetEvenIfUnreachable()

Dereference the weak pointer even if it is RF_PendingKill or RF_Unreachable

Protected function Const

int32

 

GetObjectIndex()

Public function Const

bool

 

HasSameIndexAndSerialNumber

(
    const FWeakObjectPtr& Other
)

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

Public function Const

bool

 

IsExplicitlyNull()

Returns true if this pointer was explicitly assigned to null, was reset, or was never initialized.

Public function Const

bool

 

IsStale

(
    bool bIncludingIfPendingKill,
    bool bThreadsafeTest
)

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.

Public function Const

bool

 

IsValid

(
    bool bEvenIfPendingKill,
    bool bThreadsafeTest
)

Test if this points to a live UObject

Public function Const

bool

 

IsValid()

Test if this points to a live UObject.

Public function

void

 

Reset()

Reset the weak pointer back to the null state

Public function

void

 

Serialize

(
    FArchive& Ar
)

Weak object pointer serialization.

Operators

Name Description

Public function Const

bool

 

operator!=

(
    const FWeakObjectPtr& Other
)

Compare weak pointers for inequality

Public function

void

 

operator=

(
    const FWeakObjectPtr& Other
)

Construct from another weak pointer

Public function

void

 

operator=

(
    const UObject* Object
)

Copy from an object pointer

Public function Const

bool

 

operator==

(
    const FWeakObjectPtr& Other
)

Compare weak pointers for equality.

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