Navigation
API > API/Runtime > API/Runtime/CoreUObject
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.
| Name | FWeakObjectPtr |
| Type | struct |
| Header File | /Engine/Source/Runtime/CoreUObject/Public/UObject/WeakObjectPtr.h |
| Include Path | #include "UObject/WeakObjectPtr.h" |
Syntax
struct FWeakObjectPtr
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
| Null constructor | UObject/WeakObjectPtr.h | ||
FWeakObjectPtr
(
const FWeakObjectPtr& Other |
Construct from another weak pointer | UObject/WeakObjectPtr.h | |
FWeakObjectPtr
(
TObjectPtr< T > Object |
UObject/WeakObjectPtr.h | ||
FWeakObjectPtr
(
const UObject* Object |
UObject/WeakObjectPtr.h | ||
FWeakObjectPtr
(
FObjectPtr Object |
Construct from an object pointer or something that can be implicitly converted to an object pointer | UObject/WeakObjectPtr.h | |
FWeakObjectPtr
(
int |
UObject/WeakObjectPtr.h | ||
FWeakObjectPtr
(
TYPE_OF_NULLPTR |
Construct from nullptr or something that can be implicitly converted to nullptr (eg: NULL) | UObject/WeakObjectPtr.h |
Variables
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| ObjectIndex | int32 | UObject/WeakObjectPtr.h | ||
| ObjectSerialNumber | int32 | UObject/WeakObjectPtr.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
| Dereference the weak pointer. | UObject/WeakObjectPtr.h | ||
| Dereference the weak pointer. This is an optimized version implying bEvenIfGarbage=false. | UObject/WeakObjectPtr.h | ||
UObject * GetEvenIfUnreachable() |
Dereference the weak pointer even if it is marked as Garbage or Unreachable | UObject/WeakObjectPtr.h | |
uint32 GetTypeHash() |
Hash function. | UObject/WeakObjectPtr.h | |
bool HasSameIndexAndSerialNumber
(
const FWeakObjectPtr& Other |
Returns true if two weak pointers were originally set to the same object, even if they are now stale | UObject/WeakObjectPtr.h | |
bool IsExplicitlyNull () |
Returns true if this pointer was explicitly assigned to null, was reset, or was never initialized. | UObject/WeakObjectPtr.h | |
bool IsRemote() |
UObject/WeakObjectPtr.h | ||
bool IsStale
(
bool bIncludingGarbage, |
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. | UObject/WeakObjectPtr.h | |
bool IsValid () |
Test if this points to a live UObject. | UObject/WeakObjectPtr.h | |
bool IsValid
(
bool bEvenIfGarbage, |
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. | UObject/WeakObjectPtr.h | |
TStrongObjectPtr< UObject > Pin
(
bool bEvenIfGarbage |
Get a strong object ptr to the weak pointer. | UObject/WeakObjectPtr.h | |
TStrongObjectPtr< UObject > Pin () |
Get a strong object ptr to the weak pointer. | UObject/WeakObjectPtr.h | |
TStrongObjectPtr< UObject > PinEvenIfUnreachable() |
Get a strong object ptr even if it is marked as Garbage or Unreachable | UObject/WeakObjectPtr.h | |
void Reset() |
Reset the weak pointer back to the null state | UObject/WeakObjectPtr.h | |
| Weak object pointer serialization. | UObject/WeakObjectPtr.h | ||
TStrongObjectPtr< UObject > TryPin
(
bool& bOutPinValid |
Attempt to get a strong object ptr to the weak pointer, but only if garbage collection is not in progress. | UObject/WeakObjectPtr.h | |
TStrongObjectPtr< UObject > TryPin
(
bool& bOutPinValid, |
Attempt to get a strong object ptr to the weak pointer, but only if garbage collection is not in progress. | UObject/WeakObjectPtr.h | |
bool TryPinEvenIfUnreachable
(
TStrongObjectPtr< UObject >& OutResult |
Attempt to get a strong object ptr even if it is marked as Garbage or Unreachable, but only if garbage collection is not in progress | UObject/WeakObjectPtr.h |
Protected
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
int32 GetObjectIndex() |
UObject/WeakObjectPtr.h |
Operators
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
operator bool() |
This is explicitly not added to avoid resolving weak pointers too often - use Get() once in a function. | UObject/WeakObjectPtr.h | |
bool operator!=
(
const FWeakObjectPtr& Other |
Compare weak pointers for inequality | UObject/WeakObjectPtr.h | |
void operator=
(
FObjectPtr Object |
Copy from an object pointer | UObject/WeakObjectPtr.h | |
| UObject/WeakObjectPtr.h | |||
void operator=
(
TObjectPtr< T > Object |
UObject/WeakObjectPtr.h | ||
FWeakObjectPtr & operator=
(
const FWeakObjectPtr& Other |
Construct from another weak pointer | UObject/WeakObjectPtr.h | |
bool operator==
(
const FWeakObjectPtr& Other |
Compare weak pointers for equality. | UObject/WeakObjectPtr.h |