![]() |
UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
|
#include <WeakObjectPtr.h>
Protected Member Functions | |
| UE_FORCEINLINE_HINT int32 | GetObjectIndex () const |
Friends | |
| template<class , class > | |
| struct | TWeakObjectPtr |
| struct | FObjectKey |
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.
|
default |
|
inline |
|
inline |
|
inline |
Construct from an object pointer or something that can be implicitly converted to an object pointer
| Object | object to create a weak pointer to |
|
inline |
|
inline |
|
default |
Construct from another weak pointer
| Other | weak pointer to copy from |
| UObject * FWeakObjectPtr::Get | ( | ) | const |
Dereference the weak pointer. This is an optimized version implying bEvenIfGarbage=false.
Dereference the weak pointer.
| bEvenIfGarbage | if this is true, Garbage objects are considered valid |
| UObject * FWeakObjectPtr::GetEvenIfUnreachable | ( | ) | const |
Dereference the weak pointer even if it is marked as Garbage or Unreachable
|
inlineprotected |
|
inline |
Hash function.
|
inline |
Returns true if two weak pointers were originally set to the same object, even if they are now stale
| Other | weak pointer to compare to |
|
inline |
|
inline |
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.
| bIncludingGarbage | if this is false, Garbage objects are NOT considered stale |
| bThreadsafeTest | set it to true when testing outside of Game Thread. Results in false if WeakObjPtr point to an existing object (no flags checked) |
| bool FWeakObjectPtr::IsValid | ( | ) | const |
Test if this points to a live UObject. This is an optimized version implying bEvenIfGarbage=false, bThreadsafeTest=false. This should be done only when needed as excess resolution of the underlying pointer can cause performance issues. Note that IsValid can not be used on another thread as it will incorrectly return false during the mark phase of the GC due to the Unreachable flag being set. (see bThreadsafeTest above)
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.
| bEvenIfGarbage | if this is true, Garbage objects are considered valid. When false, an object is considered invalid as soon as it is marked for destruction. |
| bThreadsafeTest | if true then function will just give you information whether referenced UObject is gone forever (return false) or if it is still there (return true, no object flags checked). This is required as without it IsValid can return false during the mark phase of the GC due to the presence of the Unreachable flag. |
|
explicitdelete |
|
inline |
Compare weak pointers for inequality
| Other | weak pointer to compare to |
|
default |
Construct from another weak pointer
| Other | weak pointer to copy from |
|
inline |
| void FWeakObjectPtr::operator= | ( | FObjectPtr | ObjectPtr | ) |
Copy from an object pointer
| Object | object to create a weak pointer to |
|
inline |
|
inline |
Compare weak pointers for equality. If both pointers would return nullptr from Get() they count as equal even if they were not initialized to the same object.
| Other | weak pointer to compare to |
| TStrongObjectPtr< UObject > FWeakObjectPtr::Pin | ( | ) | const |
Get a strong object ptr to the weak pointer. This is an optimized version implying bEvenIfGarbage=false.
| TStrongObjectPtr< UObject > FWeakObjectPtr::Pin | ( | bool | bEvenIfGarbage | ) | const |
Get a strong object ptr to the weak pointer.
| bEvenIfGarbage | if this is true, Garbage objects are considered valid |
| TStrongObjectPtr< UObject > FWeakObjectPtr::PinEvenIfUnreachable | ( | ) | const |
|
inline |
Reset the weak pointer back to the null state
Weak object pointer serialization. Weak object pointers only have weak references to objects and won't serialize the object when gathering references for garbage collection. So in many cases, you don't need to bother serializing weak object pointers. However, serialization is required if you want to load and save your object.
| class TStrongObjectPtr< UObject > FWeakObjectPtr::TryPin | ( | bool & | bOutPinValid | ) | const |
Attempt to get a strong object ptr to the weak pointer, but only if garbage collection is not in progress. This is an optimized version implying bEvenIfGarbage=false.
| bOutPinValid | will be true if the pin attempt was successful, and false if it was blocked by garbage collection |
| class TStrongObjectPtr< UObject > FWeakObjectPtr::TryPin | ( | bool & | bOutPinValid, |
| bool | bEvenIfGarbage | ||
| ) | const |
Attempt to get a strong object ptr to the weak pointer, but only if garbage collection is not in progress.
| bEvenIfGarbage | if this is true, Garbage objects are considered valid |
| bOutPinValid | will be true if the pin attempt was successful, and false if it was blocked by garbage collection |
| bool FWeakObjectPtr::TryPinEvenIfUnreachable | ( | class TStrongObjectPtr< UObject > & | OutResult | ) | const |
|
friend |
|
friend |