UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
WorldPartitionStreamingPolicy.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
10#pragma once
11
12#include "Async/TaskGraphFwd.h"
13#include "Containers/Set.h"
14#include "Misc/CoreDelegates.h"
20#include "WorldPartitionStreamingPolicy.generated.h"
21
22class UWorldPartition;
24
25USTRUCT()
27{
29
32 bool Contains(const UWorldPartitionRuntimeCell* InCell) const { return Cells.Contains(InCell); }
33 void OnAddedToWorld(const UWorldPartitionRuntimeCell* InCell);
34 void OnRemovedFromWorld(const UWorldPartitionRuntimeCell* InCell);
35 void Reset();
36
38 const TSet<const UWorldPartitionRuntimeCell*>& GetPendingAddToWorldCells() const { return PendingAddToWorldCells; }
39
40private:
41
44
45 TSet<const UWorldPartitionRuntimeCell*> PendingAddToWorldCells;
46};
47
48USTRUCT()
50{
52
55
58
60 TArray<TObjectPtr<const UWorldPartitionRuntimeCell>> ToDeactivateCells;
61
64
66 bool bBlockOnSlowStreaming = false;
67
68 bool bUpdateServerEpoch = false;
69
70 bool IsEmpty() const;
71 void Reset();
72};
73
74USTRUCT()
91
92UCLASS(Abstract, Within = WorldPartition)
94{
96
97public:
99 virtual void UpdateStreamingState();
100 virtual bool CanAddCellToWorld(const UWorldPartitionRuntimeCell* InCell) const;
101 virtual bool DrawRuntimeHash2D(FWorldPartitionDraw2DContext& DrawContext);
102 virtual void DrawRuntimeHash3D();
103 virtual void DrawRuntimeCellsDetails(class UCanvas* Canvas, FVector2D& Offset) {}
104
105 virtual bool IsStreamingCompleted(const TArray<FWorldPartitionStreamingSource>* InStreamingSources) const;
106 virtual bool IsStreamingCompleted(EWorldPartitionRuntimeCellState QueryState, const TArray<FWorldPartitionStreamingQuerySource>& QuerySources, bool bExactState = true) const;
107
108 virtual void OnCellShown(const UWorldPartitionRuntimeCell* InCell);
109 virtual void OnCellHidden(const UWorldPartitionRuntimeCell* InCell);
110
111 UE_DEPRECATED(5.3, "CanAddLoadedLevelToWorld is deprecated.")
112 virtual bool CanAddLoadedLevelToWorld(class ULevel* InLevel) const { return true; }
113
114#if WITH_EDITOR
116
117 // PIE/Game methods
120 virtual void RemapSoftObjectPath(FSoftObjectPath& ObjectPath) const {}
121
122 UE_DEPRECATED(5.4, "Use StoreStreamingContentToExternalStreamingObject instead.")
126#endif
127
128#if !UE_BUILD_SHIPPING
129 virtual void GetOnScreenMessages(FCoreDelegates::FSeverityMessageMap& OutMessages);
130#endif
131
132 // Editor/Runtime conversions
133 virtual bool ConvertEditorPathToRuntimePath(const FSoftObjectPath& InPath, FSoftObjectPath& OutPath) const { return false; }
134 virtual UObject* GetSubObject(const TCHAR* SubObjectPath) { return nullptr; }
135
136 const TArray<FWorldPartitionStreamingSource>& GetStreamingSources() const { return CurrentState.StreamingSources; }
137
138 EWorldPartitionStreamingPerformance GetStreamingPerformance() const { return CurrentStreamingPerformance; }
139
140 static bool IsUpdateStreamingOptimEnabled();
141
142 virtual bool InjectExternalStreamingObject(URuntimeHashExternalStreamingObjectBase* ExternalStreamingObject) { return true; }
143 virtual bool RemoveExternalStreamingObject(URuntimeHashExternalStreamingObjectBase* ExternalStreamingObject) { return true; }
144
146
147protected:
148 virtual void SetCellStateToLoaded(const UWorldPartitionRuntimeCell* InCell, int32& InOutMaxCellsToLoad);
149 virtual void SetCellStateToActivated(const UWorldPartitionRuntimeCell* InCell, int32& InOutMaxCellsToLoad);
150 virtual void SetCellsStateToUnloaded(const TArray<TObjectPtr<const UWorldPartitionRuntimeCell>>& ToUnloadCells);
153 virtual void UpdateStreamingSources(bool bCanOptimizeUpdate);
154
155 UE_DEPRECATED(5.6, "Use version that also sets if streaming should block on slow loading")
157 void UpdateStreamingPerformance(EWorldPartitionStreamingPerformance NewStreamingPerformance, bool bBlockOnSlowStreaming);
158 bool IsInBlockTillLevelStreamingCompleted(bool bIsCausedByBadStreamingPerformance = false) const;
159
160 // Outer World Partition
162
163private:
164 enum class EAsyncUpdateTaskState
165 {
166 None,
167 Pending,
168 Started
169 };
170
171 struct FUpdateStreamingStateParams
172 {
174 FUpdateStreamingStateParams& SetRequiredWorldDataLayersEffectiveStatesCopy(bool bInRequiredEffectiveStatesCopy);
175
176 const UWorld* World;
177 const UWorldPartitionRuntimeHash* RuntimeHash;
178 const bool bCanStream;
179 const bool bIsServer;
180 const bool bIsStreamingInEnabled;
181 const bool bIsServerStreamingEnabled;
182 const bool bIsServerStreamingOutEnabled;
183 const bool bIsBlockingCausedByBadStreamingPerformance;
184 const bool bIsPlaybackEnabled;
185 const bool bMatchStarted;
186 const bool bShouldMergeStreamingSourceInfo;
187 const int32 PolicyUpdateStreamingStateEpoch;
188 const EWorldPartitionDataLayersLogicOperator DataLayersLogicOperator;
189 const FTransform WorldPartitionInstanceTransform;
191 const TSet<FName>& ServerDisallowedStreamingOutDataLayers;
192 TSet<const UWorldPartitionRuntimeCell*>& FrameActivateCells;
194 TSet<const UWorldPartitionRuntimeCell*>& FrameAnalysePerformanceCells;
195
196 const FWorldDataLayersEffectiveStates& GetWorldDataLayersEffectiveStates() const { return WorldDataLayersEffectiveStatesCopy.Get(WorldDataLayersEffectiveStatesRef); }
197 private:
198 const FWorldDataLayersEffectiveStates& WorldDataLayersEffectiveStatesRef;
199 TOptional<FWorldDataLayersEffectiveStates> WorldDataLayersEffectiveStatesCopy;
200 };
201
202 // Update optimization
203 uint32 ComputeUpdateStreamingHash(bool bCanOptimizeUpdate) const;
204 int32 ComputeServerStreamingEnabledEpoch() const;
205
206 void OnStreamingStateUpdated();
207 void OnPreChangeStreamingContent();
208 bool WaitForAsyncUpdateStreamingState();
209 void PostUpdateStreamingStateInternal_GameThread(FWorldPartitionUpdateStreamingTargetState& InOutTargetState);
210 const TSet<FName>& GetServerDisallowedStreamingOutDataLayers() const;
211 static void UpdateStreamingStateInternal(const FUpdateStreamingStateParams& InParams, FWorldPartitionUpdateStreamingTargetState& OutTargetState);
212
213 // Current streaming state
216
217 // Current streaming performance
219 EWorldPartitionStreamingPerformance CurrentStreamingPerformance;
220
221 // Current block on slow streaming
223 bool bCurrentBlockOnSlowStreaming;
224
225 // Target state
228
229 // Asynchronous update task input payload
231 FWorldPartitionUpdateStreamingCurrentState AsyncTaskCurrentState;
232
233 // Asynchronous update task output payload
236
237 UPROPERTY()
238 bool bShouldMergeStreamingSourceInfo;
239
240 bool bCriticalPerformanceRequestedBlockTillOnWorld;
241 int32 CriticalPerformanceBlockTillLevelStreamingCompletedEpoch;
242 int32 ProcessedToLoadCells; // Used to know if last update fully processed ToLoadCells
243 int32 ProcessedToActivateCells; // Used to know if last update fully processed ToActivateCells
244 int32 ServerStreamingStateEpoch;
245 int32 ServerStreamingEnabledEpoch;
246 uint32 UpdateStreamingHash;
247 uint32 UpdateStreamingSourcesHash;
248 uint32 UpdateStreamingStateCounter;
249
250 // Asynchronous update task
251 EAsyncUpdateTaskState AsyncUpdateTaskState;
252 UE::Tasks::TTask<void> AsyncUpdateStreamingStateTask;
253
254 int32 AsyncShouldSkipUpdateCounter;
255
256 mutable TOptional<TSet<FName>> CachedServerDisallowStreamingOutDataLayers;
257 // Used internally by UpdateStreamingStateInternal (avoids re-allocations)
258 mutable TSet<const UWorldPartitionRuntimeCell*> FrameActivateCells;
259 mutable TSet<const UWorldPartitionRuntimeCell*> FrameLoadCells;
260 mutable TSet<const UWorldPartitionRuntimeCell*> FrameAnalysePerformanceCells;
261
262 // CVars to control update optimization
263 static bool IsUpdateOptimEnabled;
264 static bool IsAsyncUpdateStreamingStateEnabled;
265 static int32 ForceUpdateFrameCount;
266 static FAutoConsoleVariableRef CVarUpdateOptimEnabled;
267 static FAutoConsoleVariableRef CVarAsyncUpdateStreamingStateEnabled;
268 static FAutoConsoleVariableRef CVarForceUpdateFrameCount;
269
270#if !UE_BUILD_SHIPPING
272
273 double OnScreenMessageStartTime;
274 EWorldPartitionStreamingPerformance OnScreenMessageStreamingPerformance;
275 bool bOnScreenMessageShouldBlock;
276#endif
277
278 friend class UWorldPartition;
280};
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define PURE_VIRTUAL(func,...)
Definition CoreMiscDefines.h:103
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
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
const bool
Definition NetworkReplayStreaming.h:178
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
#define USTRUCT(...)
Definition ObjectMacros.h:746
#define GENERATED_USTRUCT_BODY(...)
Definition ObjectMacros.h:767
UClass * StaticClass()
Definition ReflectedTypeAccessors.h:13
uint32 Offset
Definition VulkanMemory.cpp:4033
EWorldPartitionRuntimeCellState
Definition WorldPartitionRuntimeCell.h:202
EWorldPartitionStreamingPerformance
Definition WorldPartitionRuntimeHash.h:39
EWorldPartitionDataLayersLogicOperator
Definition WorldPartition.h:89
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition IConsoleManager.h:1580
TMultiMap< EOnScreenMessageSeverity, FText > FSeverityMessageMap
Definition CoreDelegates.h:513
Definition NameTypes.h:617
Definition WorldPartitionDraw2DContext.h:117
Definition Array.h:670
Definition SubclassOf.h:30
Definition Canvas.h:159
Definition Level.h:423
Definition Object.h:95
Definition WorldPartitionRuntimeHash.h:61
Definition WorldPartitionRuntimeCell.h:236
Definition WorldPartitionRuntimeHash.h:192
Definition WorldPartitionStreamingPolicy.h:94
EWorldPartitionStreamingPerformance GetStreamingPerformance() const
Definition WorldPartitionStreamingPolicy.h:138
virtual bool ConvertEditorPathToRuntimePath(const FSoftObjectPath &InPath, FSoftObjectPath &OutPath) const
Definition WorldPartitionStreamingPolicy.h:133
virtual bool InjectExternalStreamingObject(URuntimeHashExternalStreamingObjectBase *ExternalStreamingObject)
Definition WorldPartitionStreamingPolicy.h:142
virtual bool RemoveExternalStreamingObject(URuntimeHashExternalStreamingObjectBase *ExternalStreamingObject)
Definition WorldPartitionStreamingPolicy.h:143
virtual void SetShouldMergeStreamingSourceInfo(bool bInShouldMergeStreamingSourceInfo)
Definition WorldPartitionStreamingPolicy.h:145
const TArray< FWorldPartitionStreamingSource > & GetStreamingSources() const
Definition WorldPartitionStreamingPolicy.h:136
virtual UObject * GetSubObject(const TCHAR *SubObjectPath)
Definition WorldPartitionStreamingPolicy.h:134
virtual void DrawRuntimeCellsDetails(class UCanvas *Canvas, FVector2D &Offset)
Definition WorldPartitionStreamingPolicy.h:103
Definition WorldPartitionSubsystem.h:52
Definition WorldPartition.h:142
Definition World.h:918
Definition AdvancedWidgetsModule.cpp:13
Definition WorldPartition.cpp:74
@ false
Definition radaudio_common.h:23
Definition WorldPartitionStreamingPolicy.h:27
bool Contains(const UWorldPartitionRuntimeCell *InCell) const
Definition WorldPartitionStreamingPolicy.h:32
const TSet< const UWorldPartitionRuntimeCell * > & GetPendingAddToWorldCells() const
Definition WorldPartitionStreamingPolicy.h:38
const TSet< TObjectPtr< const UWorldPartitionRuntimeCell > > & GetCells() const
Definition WorldPartitionStreamingPolicy.h:37
Definition WorldPartitionActorContainerID.h:44
Definition SoftObjectPath.h:56
Definition WorldDataLayers.h:51
Definition WorldPartitionRuntimeContainerResolving.h:65
Definition WorldPartitionStreamingSource.h:344
Definition WorldPartitionStreamingPolicy.h:76
Definition WorldPartitionStreamingPolicy.h:50
Definition ObjectPtr.h:488
Definition Optional.h:131