UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
UObjectThreadContext.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 UnAsyncLoading.cpp: Unreal async loading code.
5=============================================================================*/
6
7#pragma once
8
9#include "Containers/Array.h"
11#include "Containers/Map.h"
12#include "Containers/Set.h"
13#include "CoreMinimal.h"
14#include "CoreTypes.h"
15#include "HAL/PlatformCrt.h"
17#include "HAL/ThreadSingleton.h"
18#include "Logging/LogCategory.h"
19#include "Logging/LogMacros.h"
26
27class FLinkerLoad;
28class FName;
31class UObject;
33
35
37
39{
41
44#if WITH_EDITORONLY_DATA
45 // Remove declaration of manual constructors after removing deprecated PackagesMarkedEditorOnlyByOtherPackage
48#endif
49
51 TArray<FObjectInitializer*> InitializerStack;
52
53public:
54
59 {
60 InitializerStack.Pop(EAllowShrinking::No);
61 }
62
68 {
69 InitializerStack.Push(Initializer);
70 }
71
77 {
78 return InitializerStack.Num() ? InitializerStack.Last() : nullptr;
79 }
80
86 {
87 if (FObjectInitializer* ObjectInitializerPtr = TopInitializer())
88 {
90 }
91 return ReportNull();
92 }
93
98 /* Global int to track how many nested loads we're doing by triggering an async load and immediately flushing that request. */
100 /* Global flag so that FObjectFinders know if they are called from inside the UObject constructors or not. */
102 /* Object that is currently being constructed with ObjectInitializer */
112
113#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
118#endif
119#if WITH_EDITORONLY_DATA
120 UE_DEPRECATED(5.5, "No longer used; skiponlyeditoronly is used instead and tracks editoronly references via savepackage results.")
122#endif
123
126 {
127 return SerializeContext;
128 }
129
130private:
133
136};
137
140{
142
143private:
144
147
150
152 int32 RefCount;
153
155 int32 ImportCount;
157 int32 ForcedExportCount;
159 int32 ObjBeginLoadCount;
161 TArray<UObject*> ObjectsLoaded;
163 TArray<FLinkerLoad*> DelayedLinkerClosePackages;
164
165public:
166
179#if WITH_EDITORONLY_DATA
198#endif
199
203
205 bool HasStartedLoading() const
206 {
207 return ObjBeginLoadCount > 0;
208 }
210 {
211 return ObjBeginLoadCount;
212 }
213
216
218 {
219 return ++ImportCount;
220 }
222 {
223 ImportCount = 0;
224 }
225
227 {
228 return ++ForcedExportCount;
229 }
231 {
232 ForcedExportCount = 0;
233 }
234
236 {
237 return ImportCount || ForcedExportCount;
238 }
239
240 bool HasLoadedObjects() const
241 {
242 return !!ObjectsLoaded.Num();
243 }
244
246
249 {
250 return ObjectsLoaded;
251 }
252
254 {
255 InLoadedObject.Append(ObjectsLoaded);
256 ObjectsLoaded.Reset();
257 }
258
260 {
261 ObjectsLoaded.Reserve(InReserveSize);
262 }
263
265 {
266 return ObjectsLoaded.Num();
267 }
268
270 {
271 DelayedLinkerClosePackages.AddUnique(InLinker);
272 }
273
275 {
276 DelayedLinkerClosePackages.Remove(InLinker);
277 }
278
283
285 UE_DEPRECATED(5.5, "AttachLinker is not necessary. Remove calls to it.")
287
289 UE_DEPRECATED(5.5, "DetachLinker is not necessary. Remove calls to it.")
291
295
296 //~ TRefCountPtr interface
298 {
299 return ++RefCount;
300 }
302 {
303 int32 CurrentRefCount = --RefCount;
305 if (CurrentRefCount == 0)
306 {
307 delete this;
308 }
309 return CurrentRefCount;
310 }
312 {
313 return RefCount;
314 }
315 //~ TRefCountPtr interface
316};
#define check(expr)
Definition AssertionMacros.h:314
#define UE_INTERNAL
Definition CoreMiscDefines.h:345
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:361
EInternalObjectFlags
Definition ObjectMacros.h:631
#define UE_DECLARE_THREAD_SINGLETON_TLS(Type, Api)
Definition ThreadSingleton.h:35
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition LinkerLoad.h:124
Definition NameTypes.h:617
Definition UObjectGlobals.h:1292
Definition UObjectThreadContext.h:39
int32 IsInConstructor
Definition UObjectThreadContext.h:101
IAsyncPackageLoader * AsyncPackageLoader
Definition UObjectThreadContext.h:109
void PushInitializer(FObjectInitializer *Initializer)
Definition UObjectThreadContext.h:67
TArray< UObject *, TInlineAllocator< 16 > > PostInitPropertiesCheck
Definition UObjectThreadContext.h:115
FObjectInitializer & TopInitializerChecked()
Definition UObjectThreadContext.h:85
TArray< UObject *, TInlineAllocator< 16 > > DebugPostLoad
Definition UObjectThreadContext.h:117
bool IsDeletingLinkers
Definition UObjectThreadContext.h:97
void * AsyncPackage
Definition UObjectThreadContext.h:107
FUObjectSerializeContext * GetSerializeContext()
Definition UObjectThreadContext.h:125
UObject * ConstructedObject
Definition UObjectThreadContext.h:103
int32 SyncLoadUsingAsyncLoaderCount
Definition UObjectThreadContext.h:99
UObject * CurrentlyPostLoadedObjectByALT
Definition UObjectThreadContext.h:105
void PopInitializer()
Definition UObjectThreadContext.h:58
FObjectInitializer * TopInitializer()
Definition UObjectThreadContext.h:76
bool IsRoutingPostLoad
Definition UObjectThreadContext.h:95
Definition AsyncPackageLoader.h:88
Definition Array.h:670
SizeType Remove(const ElementType &Item)
Definition Array.h:3091
UE_REWRITE SizeType Num() const
Definition Array.h:1144
UE_NODEBUG UE_FORCEINLINE_HINT ElementType & Last(SizeType IndexFromTheEnd=0) UE_LIFETIMEBOUND
Definition Array.h:1263
UE_NODEBUG UE_FORCEINLINE_HINT void Push(ElementType &&Item)
Definition Array.h:1224
void Reset(SizeType NewSize=0)
Definition Array.h:2246
ElementType Pop(EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:1196
UE_FORCEINLINE_HINT SizeType AddUnique(ElementType &&Item)
Definition Array.h:2993
UE_FORCEINLINE_HINT void Reserve(SizeType Number)
Definition Array.h:3016
Definition UnrealString.h.inl:34
Definition RefCounting.h:454
Definition ThreadSingleton.h:44
Definition PropertyPathName.h:57
Definition Object.h:95
Definition UObjectThreadContext.h:140
COREUOBJECT_API int32 IncrementBeginLoadCount()
Definition UObjectThreadContext.cpp:78
void MoveDelayedLinkerClosePackages(TArray< class FLinkerLoad * > &OutDelayedLinkerClosePackages)
Definition UObjectThreadContext.h:279
UObject * SerializedObject
Definition UObjectThreadContext.h:168
int32 IncrementImportCount()
Definition UObjectThreadContext.h:217
int32 IncrementForcedExportCount()
Definition UObjectThreadContext.h:226
COREUOBJECT_API void AddUniqueLoadedObjects(const TArray< UObject * > &InObjects)
Definition UObjectThreadContext.cpp:88
COREUOBJECT_API void AttachLinker(FLinkerLoad *InLinker)
Definition UObjectThreadContext.cpp:115
COREUOBJECT_API bool PRIVATE_PatchNewObjectIntoExport(UObject *OldObject, UObject *NewObject)
Definition UObjectThreadContext.cpp:102
bool HasPendingImportsOrForcedExports() const
Definition UObjectThreadContext.h:235
COREUOBJECT_API int32 DecrementBeginLoadCount()
Definition UObjectThreadContext.cpp:82
TArray< UObject * > & PRIVATE_GetObjectsLoadedInternalUseOnly()
Definition UObjectThreadContext.h:248
int32 GetRefCount() const
Definition UObjectThreadContext.h:311
FLinkerLoad * SerializedImportLinker
Definition UObjectThreadContext.h:174
void ReserveObjectsLoaded(int32 InReserveSize)
Definition UObjectThreadContext.h:259
int32 GetNumObjectsLoaded() const
Definition UObjectThreadContext.h:264
FLinkerLoad * SerializedExportLinker
Definition UObjectThreadContext.h:178
int32 SerializedExportIndex
Definition UObjectThreadContext.h:176
void RemoveDelayedLinkerClosePackage(class FLinkerLoad *InLinker)
Definition UObjectThreadContext.h:274
COREUOBJECT_API void DetachLinker(FLinkerLoad *InLinker)
Definition UObjectThreadContext.cpp:120
void ResetForcedExports()
Definition UObjectThreadContext.h:230
int32 AddRef()
Definition UObjectThreadContext.h:297
void ResetImportCount()
Definition UObjectThreadContext.h:221
int32 Release()
Definition UObjectThreadContext.h:301
int32 GetBeginLoadCount() const
Definition UObjectThreadContext.h:209
bool HasStartedLoading() const
Definition UObjectThreadContext.h:205
int32 SerializedImportIndex
Definition UObjectThreadContext.h:172
void AppendLoadedObjectsAndEmpty(TArray< UObject * > &InLoadedObject)
Definition UObjectThreadContext.h:253
FLinkerLoad * SerializedPackageLinker
Definition UObjectThreadContext.h:170
COREUOBJECT_API void DetachFromLinkers()
Definition UObjectThreadContext.cpp:124
friend class FUObjectThreadContext
Definition UObjectThreadContext.h:141
void AddDelayedLinkerClosePackage(class FLinkerLoad *InLinker)
Definition UObjectThreadContext.h:269
COREUOBJECT_API void AddLoadedObject(UObject *InObject)
Definition UObjectThreadContext.cpp:97
bool HasLoadedObjects() const
Definition UObjectThreadContext.h:240