UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ObjectKey.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
7
8#include <type_traits>
9
10struct FObjectKey;
11
13{
14 FObjectKey MakeObjectKey(int32 ObjectIndex, int32 ObjectSerialNumber);
15}
16
19{
20public:
22 inline FObjectKey()
23 : ObjectIndex(UE::Core::Private::InvalidWeakObjectIndex)
24 , ObjectSerialNumber(0)
25 {
26 }
27
29 inline FObjectKey(const UObject* Object)
30 : ObjectIndex(UE::Core::Private::InvalidWeakObjectIndex)
31 , ObjectSerialNumber(0)
32 {
33 if (Object)
34 {
36 ObjectIndex = Weak.ObjectIndex;
37 ObjectSerialNumber = Weak.ObjectSerialNumber;
38#if UE_WITH_REMOTE_OBJECT_HANDLE
39 RemoteId = Weak.ObjectRemoteId;
40#endif
41 }
42 }
43 template <
44 typename U
45 UE_REQUIRES(std::is_convertible_v<U, const UObject*>)
46 >
51
53 inline bool operator==(const FObjectKey& Other) const
54 {
55#if UE_WITH_REMOTE_OBJECT_HANDLE
56 return RemoteId == Other.RemoteId;
57#else
58 return ObjectIndex == Other.ObjectIndex && ObjectSerialNumber == Other.ObjectSerialNumber;
59#endif
60 }
61
63 inline bool operator!=(const FObjectKey& Other) const
64 {
65#if UE_WITH_REMOTE_OBJECT_HANDLE
66 return RemoteId != Other.RemoteId;
67#else
68 return ObjectIndex != Other.ObjectIndex || ObjectSerialNumber != Other.ObjectSerialNumber;
69#endif
70 }
71
73 inline bool operator<(const FObjectKey& Other) const
74 {
75#if UE_WITH_REMOTE_OBJECT_HANDLE
76 return RemoteId < Other.RemoteId;
77#else
78 return ObjectIndex < Other.ObjectIndex || (ObjectIndex == Other.ObjectIndex && ObjectSerialNumber < Other.ObjectSerialNumber);
79#endif
80 }
81
83 inline bool operator<=(const FObjectKey& Other) const
84 {
85#if UE_WITH_REMOTE_OBJECT_HANDLE
86 return RemoteId <= Other.RemoteId;
87#else
88 return ObjectIndex <= Other.ObjectIndex || (ObjectIndex == Other.ObjectIndex && ObjectSerialNumber <= Other.ObjectSerialNumber);
89#endif
90 }
91
93 inline bool operator>(const FObjectKey& Other) const
94 {
95#if UE_WITH_REMOTE_OBJECT_HANDLE
96 return RemoteId > Other.RemoteId;
97#else
98 return ObjectIndex > Other.ObjectIndex || (ObjectIndex == Other.ObjectIndex && ObjectSerialNumber > Other.ObjectSerialNumber);
99#endif
100 }
101
103 inline bool operator>=(const FObjectKey& Other) const
104 {
105#if UE_WITH_REMOTE_OBJECT_HANDLE
106 return RemoteId >= Other.RemoteId;
107#else
108 return ObjectIndex > Other.ObjectIndex || (ObjectIndex == Other.ObjectIndex && ObjectSerialNumber >= Other.ObjectSerialNumber);
109#endif
110 }
111
112 inline friend FArchive& operator<<(FArchive& Ar, FObjectKey& Key)
113 {
114 check(!Ar.IsPersistent());
115 return Ar << Key.ObjectIndex << Key.ObjectSerialNumber
116#if UE_WITH_REMOTE_OBJECT_HANDLE
117 << Key.RemoteId
118#endif
119 ;
120 }
121
127 {
128 FWeakObjectPtr WeakPtr;
129 WeakPtr.ObjectIndex = ObjectIndex;
130 WeakPtr.ObjectSerialNumber = ObjectSerialNumber;
131#if UE_WITH_REMOTE_OBJECT_HANDLE
132 WeakPtr.ObjectRemoteId = RemoteId;
133#endif
134 return WeakPtr.Get();
135 }
136
142 {
143 FWeakObjectPtr WeakPtr;
144 WeakPtr.ObjectIndex = ObjectIndex;
145 WeakPtr.ObjectSerialNumber = ObjectSerialNumber;
146#if UE_WITH_REMOTE_OBJECT_HANDLE
147 WeakPtr.ObjectRemoteId = RemoteId;
148#endif
149 constexpr bool bEvenIfGarbage = true;
150 return WeakPtr.Get(bEvenIfGarbage);
151 }
152
153 UE_DEPRECATED(5.4, "Use ResolveObjectPtrEvenIfGarbage().")
158
164 {
165 FWeakObjectPtr WeakPtr;
166 WeakPtr.ObjectIndex = ObjectIndex;
167 WeakPtr.ObjectSerialNumber = ObjectSerialNumber;
168#if UE_WITH_REMOTE_OBJECT_HANDLE
169 WeakPtr.ObjectRemoteId = RemoteId;
170#endif
171 return WeakPtr.GetEvenIfUnreachable();
172 }
173
179 {
180 FWeakObjectPtr WeakPtr;
181 WeakPtr.ObjectIndex = ObjectIndex;
182 WeakPtr.ObjectSerialNumber = ObjectSerialNumber;
183#if UE_WITH_REMOTE_OBJECT_HANDLE
184 WeakPtr.ObjectRemoteId = RemoteId;
185#endif
186 return WeakPtr;
187 }
188
190 [[nodiscard]] friend uint32 GetTypeHash(const FObjectKey& Key)
191 {
192#if UE_WITH_REMOTE_OBJECT_HANDLE
193 return GetTypeHash(Key.RemoteId);
194#else
195 return HashCombine(Key.ObjectIndex, Key.ObjectSerialNumber);
196#endif
197 }
198
199#if UE_WITH_REMOTE_OBJECT_HANDLE
201 FRemoteObjectId GetRemoteId() const
202 {
203 return RemoteId;
204 }
205#endif
206
207private:
208#if !UE_WITH_REMOTE_OBJECT_HANDLE
209 FObjectKey(int32 Index, int32 Serial)
210 : ObjectIndex(Index)
211 , ObjectSerialNumber(Serial)
212 {
213 }
214
215 friend FObjectKey UE::CoreUObject::Private::MakeObjectKey(int32 ObjectIndex, int32 ObjectSerialNumber);
216#endif
217
218 int32 ObjectIndex;
219 int32 ObjectSerialNumber;
220#if UE_WITH_REMOTE_OBJECT_HANDLE
221 FRemoteObjectId RemoteId;
222#endif // UE_WITH_REMOTE_OBJECT_HANDLE
223};
224
226template<typename InElementType>
228{
229public:
231
234
236 template <
237 typename U
238 UE_REQUIRES(std::is_convertible_v<U, const InElementType*>)
239 >
241 : ObjectKey(ImplicitConv<const InElementType*>(Object))
242 {
243 }
244
247 {
248 return ObjectKey == Other.ObjectKey;
249 }
250
253 {
254 return ObjectKey != Other.ObjectKey;
255 }
256
259 {
260 return ObjectKey < Other.ObjectKey;
261 }
262
265 {
266 return ObjectKey <= Other.ObjectKey;
267 }
268
271 {
272 return ObjectKey > Other.ObjectKey;
273 }
274
277 {
278 return ObjectKey >= Other.ObjectKey;
279 }
280
281 //** Hash function */
282 [[nodiscard]] friend uint32 GetTypeHash(const TObjectKey& Key)
283 {
284 return GetTypeHash(Key.ObjectKey);
285 }
286
292 {
293 return (InElementType*)ObjectKey.ResolveObjectPtr();
294 }
295
301 {
302 return static_cast<InElementType*>(ObjectKey.ResolveObjectPtrEvenIfGarbage());
303 }
304
305 UE_DEPRECATED(5.4, "Use ResolveObjectPtrEvenIfGarbage().")
307 {
308 return static_cast<InElementType*>(ObjectKey.ResolveObjectPtrEvenIfGarbage());
309 }
310
311private:
312 FObjectKey ObjectKey;
313};
#define check(expr)
Definition AssertionMacros.h:314
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define UE_FORCEINLINE_HINT
Definition Platform.h:723
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UE_REQUIRES(...)
Definition Requires.h:86
constexpr uint32 HashCombine(uint32 A, uint32 C)
Definition TypeHash.h:36
UE_REWRITE constexpr T ImplicitConv(typename TIdentity< T >::Type Obj)
Definition UnrealTemplate.h:743
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
UE_FORCEINLINE_HINT bool IsPersistent() const
Definition Archive.h:300
Definition ObjectKey.h:228
UE_FORCEINLINE_HINT TObjectKey(U Object)
Definition ObjectKey.h:240
InElementType * ResolveObjectPtrEvenIfGarbage() const
Definition ObjectKey.h:300
UE_FORCEINLINE_HINT bool operator<=(const TObjectKey &Other) const
Definition ObjectKey.h:264
UE_FORCEINLINE_HINT bool operator==(const TObjectKey &Other) const
Definition ObjectKey.h:246
InElementType * ResolveObjectPtrEvenIfPendingKill() const
Definition ObjectKey.h:306
friend uint32 GetTypeHash(const TObjectKey &Key)
Definition ObjectKey.h:282
UE_FORCEINLINE_HINT TObjectKey()=default
UE_FORCEINLINE_HINT bool operator>(const TObjectKey &Other) const
Definition ObjectKey.h:270
UE_FORCEINLINE_HINT bool operator>=(const TObjectKey &Other) const
Definition ObjectKey.h:276
UE_FORCEINLINE_HINT bool operator<(const TObjectKey &Other) const
Definition ObjectKey.h:258
InElementType ElementType
Definition ObjectKey.h:230
InElementType * ResolveObjectPtr() const
Definition ObjectKey.h:291
UE_FORCEINLINE_HINT bool operator!=(const TObjectKey &Other) const
Definition ObjectKey.h:252
Definition Object.h:95
Definition OverriddenPropertySet.cpp:45
void Serial(FArchive &Ar, T *Param)
Definition DirectLinkSerialMethods.h:100
Definition CoreGlobals.cpp:268
FObjectKey MakeObjectKey(int32 ObjectIndex, int32 ObjectSerialNumber)
Definition ObjectPathId.cpp:44
Definition AdvancedWidgetsModule.cpp:13
U16 Index
Definition radfft.cpp:71
Definition ObjectKey.h:19
FObjectKey(const UObject *Object)
Definition ObjectKey.h:29
bool operator>=(const FObjectKey &Other) const
Definition ObjectKey.h:103
UObject * ResolveObjectPtr() const
Definition ObjectKey.h:126
bool operator!=(const FObjectKey &Other) const
Definition ObjectKey.h:63
UObject * ResolveObjectPtrEvenIfPendingKill() const
Definition ObjectKey.h:154
FObjectKey()
Definition ObjectKey.h:22
bool operator==(const FObjectKey &Other) const
Definition ObjectKey.h:53
friend FArchive & operator<<(FArchive &Ar, FObjectKey &Key)
Definition ObjectKey.h:112
FWeakObjectPtr GetWeakObjectPtr() const
Definition ObjectKey.h:178
UObject * ResolveObjectPtrEvenIfUnreachable() const
Definition ObjectKey.h:163
bool operator>(const FObjectKey &Other) const
Definition ObjectKey.h:93
bool operator<(const FObjectKey &Other) const
Definition ObjectKey.h:73
UE_FORCEINLINE_HINT FObjectKey(U Object)
Definition ObjectKey.h:47
bool operator<=(const FObjectKey &Other) const
Definition ObjectKey.h:83
friend uint32 GetTypeHash(const FObjectKey &Key)
Definition ObjectKey.h:190
UObject * ResolveObjectPtrEvenIfGarbage() const
Definition ObjectKey.h:141
Definition RemoteObjectTypes.h:212
Definition WeakObjectPtr.h:49
COREUOBJECT_API class UObject * GetEvenIfUnreachable() const
Definition WeakObjectPtr.cpp:127
COREUOBJECT_API class UObject * Get(bool bEvenIfGarbage) const
Definition WeakObjectPtr.cpp:122