RealDocs

TWeakPtr::GetWeakPtrTypeHash

function Core Since 4.0
#include "Templates/SharedPointer.h"
Access: public Specifiers: constinline

Description

Returns a hash of the weak pointer based on the raw object address, suitable for use in TSet and TMap containers. The hash is stable as long as the object remains in memory at the same address.

Caveats & Gotchas

  • The hash is derived from the raw pointer address, not from the object's identity or content — two TWeakPtrs pointing to different objects at the same address (after destruction and reallocation) will produce the same hash, potentially causing container collisions.
  • Hashing a weak pointer that has already expired (object destroyed) hashes the dangling address still stored in Object — this is safe to call but the resulting hash is meaningless if you intend to look up a live object.

Signature

UE_FORCEINLINE_HINT uint32 GetWeakPtrTypeHash() const

Return Type

uint32

Example

Using TWeakPtr in a TSet C++
// GetTypeHash for TWeakPtr delegates to GetWeakPtrTypeHash
TSet<TWeakPtr<FMyService>> ServiceSet;
TSharedPtr<FMyService> Service = MakeShared<FMyService>();
ServiceSet.Add(Service); // hashes via GetWeakPtrTypeHash internally

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.