@@ -36,32 +36,34 @@ public:
3636 TObjectPtr(TYPE_OF_NULLPTR) : Ptr(nullptr) {}
3737 TObjectPtr(const TObjectPtr& Other) : Ptr(Other.Ptr) {}
3838 explicit TObjectPtr(ElementType* InPtr) : Ptr(InPtr) {}
39-
39+
4040 // Assignment operators
4141 TObjectPtr& operator=(const TObjectPtr& Other) { Ptr = Other.Ptr; return *this; }
4242 TObjectPtr& operator=(TYPE_OF_NULLPTR) { Ptr = nullptr; return *this; }
4343 TObjectPtr& operator=(ElementType* InPtr) { Ptr = InPtr; return *this; }
44-
45- // Pointer operators
46- ElementType& operator* () const { return * Ptr; }
47- ElementType* operator->() const { return Ptr; }
48-
49- // Conversion operator
50- operator ElementType* () const { return Ptr; }
51-
44+
45+ // Conversion operators
46+ FORCEINLINE operator T* () const { return Get(); }
47+ template <typename U>
48+ UE_OBJPTR_DEPRECATED (5.0, "Explicit cast to other raw pointer types is deprecated. Please use the Cast API or get the raw pointer with ToRawPtr and cast that instead.")
49+ explicit FORCEINLINE operator U* () const { return (U* )Get(); }
50+ explicit FORCEINLINE operator UPTRINT() const { return (UPTRINT)Get(); }
51+ FORCEINLINE T* operator->() const { return Get(); }
52+ FORCEINLINE T& operator* () const { return * Get(); }
53+
5254 // Comparison operators
5355 bool operator==(const TObjectPtr& Other) const { return Ptr == Other.Ptr; }
5456 bool operator!=(const TObjectPtr& Other) const { return Ptr != Other.Ptr; }
5557 bool operator==(const ElementType* InPtr) const { return Ptr == InPtr; }
5658 bool operator!=(const ElementType* InPtr) const { return Ptr != InPtr; }
5759 bool operator==(TYPE_OF_NULLPTR) const { return Ptr == nullptr; }
5860 bool operator!=(TYPE_OF_NULLPTR) const { return Ptr != nullptr; }
59-
60- // Additional API compatibility
61+
62+ // Additional API compatibility with UE's TObjectPtr
6163 bool operator!() const { return Ptr == nullptr; }
6264 explicit operator bool() const { return Ptr != nullptr; }
6365 ElementType* Get() const { return Ptr; }
64-
66+
6567private:
6668 ElementType* Ptr;
6769};
@@ -92,6 +94,17 @@ private:
9294 &ObjectPtr
9395 ```
9496
97+ 3 . For pointer-to-integer conversions (e.g., formatting addresses):
98+ ``` cpp
99+ // Old
100+ uintptr_t addr = reinterpret_cast <uintptr_t >(ObjectPtr.UnderlyingObjectPointer);
101+
102+ // New
103+ uintptr_t addr = reinterpret_cast <uintptr_t >(ObjectPtr.Get());
104+ // or
105+ uintptr_t addr = reinterpret_cast <uintptr_t >(ToRawPtr(ObjectPtr)); // using helper to extract a raw pointer from TObjectPtr
106+ ```
107+
95108#### FString API Changes
96109
97110##### `GetCharArray()` Behavior Change
0 commit comments