UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
WorldPartitionRuntimeSpatialHash.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreMinimal.h"
6#include "UObject/Object.h"
8#include "Math/MathFwd.h"
10
11#include "WorldPartition.h"
16#include "WorldPartitionRuntimeSpatialHash.generated.h"
17
21
23{
24 struct FStreamingDescriptor;
25};
26
27UENUM()
34
35USTRUCT()
37{
39
41 : bUseAlignedGridLevels(true)
42 , bSnapNonAlignedGridLevelsToLowerLevels(true)
43#if WITH_EDITORONLY_DATA
46#endif
47 {}
48
49 friend bool operator==(const FSpatialHashSettings& Lhs, const FSpatialHashSettings& Rhs) = default;
50 friend bool operator!=(const FSpatialHashSettings& Lhs, const FSpatialHashSettings& Rhs) = default;
51
53
56
59
60#if WITH_EDITORONLY_DATA
61 UPROPERTY();
63
64 UPROPERTY();
66#endif
67};
68
69USTRUCT()
87
88// Disable copy of this USTRUCT by the autogenerated code.
90
94USTRUCT()
121
122// Disable copy of this USTRUCT by the autogenerated code.
124
126
130USTRUCT()
132{
134
137
138 // Move constructor.
141
142 // Move assignment.
145
146 UPROPERTY()
147 FName GridName;
148
149 UPROPERTY()
151
152 UPROPERTY()
154
155 UPROPERTY()
156 float LoadingRange;
157
158 UPROPERTY()
159 bool bBlockOnSlowStreaming;
160
161 UPROPERTY()
162 FLinearColor DebugColor;
163
164 UPROPERTY()
166
167 UPROPERTY()
169
170 UPROPERTY()
171 bool bClientOnlyVisible;
172
173 UPROPERTY()
174 int32 GridIndex;
175
176 UPROPERTY()
178
179 ENGINE_API void InjectExternalStreamingObjectGrid(const FSpatialHashStreamingGrid& InExternalObjectStreamingGrid) const;
180 ENGINE_API void RemoveExternalStreamingObjectGrid(const FSpatialHashStreamingGrid& InExternalObjectStreamingGrid) const;
181
183
184 // Used by PIE/Game
185 ENGINE_API int64 GetCellSize(int32 Level) const;
186 ENGINE_API void GetCells(const FWorldPartitionStreamingQuerySource& QuerySource, TSet<const UWorldPartitionRuntimeCell*>& OutCells, bool bEnableZCulling, FWorldPartitionQueryCache* QueryCache = nullptr) const;
187 ENGINE_API void GetCells(const TArray<FWorldPartitionStreamingSource>& Sources, UWorldPartitionRuntimeHash::FStreamingSourceCells& OutActivateCells, UWorldPartitionRuntimeHash::FStreamingSourceCells& OutLoadCells, bool bEnableZCulling, const FWorldPartitionStreamingContext& Context) const;
188 ENGINE_API void GetNonSpatiallyLoadedCells(TSet<const UWorldPartitionRuntimeCell*>& OutActivateCells, TSet<const UWorldPartitionRuntimeCell*>& OutLoadCells, const FWorldPartitionStreamingContext& Context) const;
190 ENGINE_API void Draw3D(const class UWorldPartitionRuntimeSpatialHash* Owner, const TArray<FWorldPartitionStreamingSource>& Sources, const FTransform& Transform) const;
191 ENGINE_API void ForEachRuntimeCell(TFunctionRef<bool(const UWorldPartitionRuntimeCell*)> Func) const;
192 ENGINE_API const FSquare2DGridHelper& GetGridHelper() const;
193 ENGINE_API float GetLoadingRange() const;
194
195 //~Begin Deprecation
196 UE_DEPRECATED(5.5, "Use version that takes FWorldPartitionStreamingContext instead.")
197 void GetCells(const TArray<FWorldPartitionStreamingSource>& Sources, UWorldPartitionRuntimeHash::FStreamingSourceCells& OutActivateCells, UWorldPartitionRuntimeHash::FStreamingSourceCells& OutLoadCells, bool bEnableZCulling) const {}
198 UE_DEPRECATED(5.5, "Use version that takes FWorldPartitionStreamingContext instead.")
199 void GetNonSpatiallyLoadedCells(TSet<const UWorldPartitionRuntimeCell*>& OutActivateCells, TSet<const UWorldPartitionRuntimeCell*>& OutLoadCells) const {}
200 //~End Deprecation
201
202#if WITH_EDITOR
204#endif
205
206private:
207 ENGINE_API void ForEachRuntimeCell(const FGridCellCoord& Coords, TFunctionRef<void(const UWorldPartitionRuntimeCell*)> Func) const;
208 ENGINE_API void ForEachLayerCell(const FGridCellCoord& Coords, TFunctionRef<void(const FSpatialHashStreamingGridLayerCell*)> Func) const;
209 ENGINE_API void DrawStreamingSource2D(const FBox2D& GridScreenBounds, const FSphericalSector& Shape, TFunctionRef<FVector2D(const FVector2D&)> WorldToScreen, const FColor& Color, FWorldPartitionDraw2DContext& DrawContext) const;
210 ENGINE_API void DrawStreamingSource3D(UWorld* World, const FSphericalSector& Shape, const FTransform& Transform, const FColor& Color) const;
212 ENGINE_API EWorldPartitionRuntimeCellVisualizeMode GetStreamingCellVisualizeMode() const;
213 mutable FSquare2DGridHelper* GridHelper;
214
215 // Contains cells injected at runtime from content bundles
217 mutable TArray<FSpatialHashStreamingGridLevel> InjectedGridLevels;
218
220 static class FAutoConsoleCommand OverrideLoadingRangeCommand;
221 static TMap<int32, float> OverriddenLoadingRanges;
222 static bool bAddedWorldPartitionSubsystemDeinitializedCallback;
223};
224
225// Disable copy of this USTRUCT by the autogenerated code.
226template<> struct TStructOpsTypeTraits<FSpatialHashStreamingGrid> : public TStructOpsTypeTraitsBase2<FSpatialHashStreamingGrid> { enum { WithCopy = false }; };
227
231USTRUCT()
233{
235
237#if WITH_EDITORONLY_DATA
238 : CellSize(12800)
239 , LoadingRange(25600)
240 , bBlockOnSlowStreaming(false)
241 , Origin(FVector2D::ZeroVector)
242 , Priority(0)
243 , DebugColor(FLinearColor::MakeRandomColor())
244 , bClientOnlyVisible(false)
245 , HLODLayer(nullptr)
246#endif
247 {}
248
249#if WITH_EDITORONLY_DATA
250 UPROPERTY(EditAnywhere, Category=Settings)
251 FName GridName;
252
253 UPROPERTY(EditAnywhere, Category=Settings)
254 int32 CellSize;
255
256 UPROPERTY(EditAnywhere, Category=Settings)
257 float LoadingRange;
258
260 UPROPERTY(EditAnywhere, Category=Settings)
261 bool bBlockOnSlowStreaming;
262
263 UPROPERTY(EditAnywhere, Category=Settings)
264 FVector2D Origin;
265
266 UPROPERTY(EditAnywhere, Category=Settings)
268
269 UPROPERTY(EditAnywhere, Category=Settings, meta = (IgnoreForMemberInitializationTest))
270 FLinearColor DebugColor;
271
272 UPROPERTY()
273 bool bClientOnlyVisible;
274
275 UPROPERTY()
276 TObjectPtr<const UHLODLayer> HLODLayer;
277
278 bool operator == (const FSpatialHashRuntimeGrid& Other) const;
279 bool operator != (const FSpatialHashRuntimeGrid& Other) const;
280#endif
281};
282
288{
290
291 virtual void Serialize(FArchive& Ar) override;
292
293public:
294 UPROPERTY()
296};
297
298UCLASS(MinimalAPI)
311
312UCLASS(MinimalAPI)
314{
316
317public:
318 ENGINE_API virtual void PreSave(FObjectPreSaveContext ObjectSaveContext) override;
319
320 ENGINE_API virtual void Serialize(FArchive& Ar) override;
321 ENGINE_API virtual void PostLoad() override;
322
323 UE_DEPRECATED(5.4, "ApplyCVars is deprecated")
324 void ApplyCVars() {}
325
326#if WITH_EDITOR
327 ENGINE_API virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
328
329 ENGINE_API virtual void SetDefaultValues() override;
330 virtual bool SupportsHLODs() const override { return true; }
331 ENGINE_API virtual void PreSetupHLODActors(const UWorldPartition* InWorldPartition, const UWorldPartition::FSetupHLODActorsParams& InParams) const override;
332 ENGINE_API virtual void PostSetupHLODActors(const UWorldPartition* InWorldPartition, const UWorldPartition::FSetupHLODActorsParams& InParams) const override;
333 ENGINE_API virtual bool SetupHLODActors(const IStreamingGenerationContext* StreamingGenerationContext, const UWorldPartition::FSetupHLODActorsParams& Params) const override;
334 ENGINE_API virtual FName GetDefaultGrid() const override;
335 ENGINE_API virtual bool IsValidGrid(FName GridName, const UClass* ActorClass) const override;
336 virtual bool IsValidHLODLayer(FName GridName, const FSoftObjectPath& HLODLayerPath) const override { return true; }
337 ENGINE_API virtual void DrawPreview() const override;
338
339 virtual TSubclassOf<URuntimeHashExternalStreamingObjectBase> GetExternalStreamingObjectClass() const override { return URuntimeSpatialHashExternalStreamingObject::StaticClass(); }
340
344
345 ENGINE_API bool GetPreviewGrids() const;
347
350#endif
351
352 // streaming interface
353 ENGINE_API virtual void ForEachStreamingCells(TFunctionRef<bool(const UWorldPartitionRuntimeCell*)> Func) const override;
354 ENGINE_API virtual void ForEachStreamingCellsQuery(const FWorldPartitionStreamingQuerySource& QuerySource, TFunctionRef<bool(const UWorldPartitionRuntimeCell*)> Func, FWorldPartitionQueryCache* QueryCache = nullptr) const override;
356 ENGINE_API virtual uint32 ComputeUpdateStreamingHash() const override;
357
358 ENGINE_API virtual bool InjectExternalStreamingObject(URuntimeHashExternalStreamingObjectBase* ExternalStreamingObject) override;
359 ENGINE_API virtual bool RemoveExternalStreamingObject(URuntimeHashExternalStreamingObjectBase* ExternalStreamingObject) override;
360
361 ENGINE_API uint32 GetNumGrids() const;
362
363 static ENGINE_API FString GetCellCoordString(const FGridCellCoord& InCellGlobalCoord);
364
365 ENGINE_API void ForEachStreamingGrid(TFunctionRef<void(const FSpatialHashStreamingGrid&)> Func) const;
366
367 ENGINE_API const FSpatialHashStreamingGrid* GetStreamingGridByName(FName InGridName) const;
368
369protected:
370 ENGINE_API void ForEachStreamingGrid(TFunctionRef<void(FSpatialHashStreamingGrid&)> Func);
371 ENGINE_API void ForEachStreamingGridBreakable(TFunctionRef<bool(const FSpatialHashStreamingGrid&)> Func) const;
372
373 UE_DEPRECATED(5.6, "Use version that has also flags if streaming should block (bOutShouldBlock) instead.")
376
377#if WITH_EDITOR
378 ENGINE_API virtual bool HasStreamingContent() const override;
380 ENGINE_API virtual void FlushStreamingContent() override;
382 ENGINE_API virtual void DumpStateLog(FHierarchicalLogArchive& Ar) const override;
383#endif
384
385private:
386#if WITH_EDITOR
388#endif
389
390#if WITH_EDITORONLY_DATA
391 UPROPERTY(EditAnywhere, Config, Category = RuntimeSettings)
393
396 bool bPreviewGrids;
397
400
403#endif
404
405#if WITH_EDITORONLY_DATA
407 UPROPERTY(EditAnywhere, Config, AdvancedDisplay, Category = RuntimeSettings)
409
411 UPROPERTY(EditAnywhere, Config, AdvancedDisplay, Category = RuntimeSettings)
413
415 UPROPERTY(EditAnywhere, Config, AdvancedDisplay, Category = RuntimeSettings)
417
419 UPROPERTY(EditAnywhere, Config, AdvancedDisplay, Category = RuntimeSettings)
421#endif
422
424 UPROPERTY(EditAnywhere, Config, Category = RuntimeSettings)
425 bool bEnableZCulling;
426
427protected:
428 UPROPERTY()
430
434 UPROPERTY(NonPIEDuplicateTransient)
436 mutable TMap<FName, const FSpatialHashStreamingGrid*> NameToGridMapping;
437 mutable bool bIsNameToGridMappingDirty;
438
439 ENGINE_API virtual bool SupportsWorldAssetStreaming(const FName& InTargetGrid) override;
440 ENGINE_API virtual FGuid RegisterWorldAssetStreaming(const UWorldPartition::FRegisterWorldAssetStreamingParams& InParams) override;
441 ENGINE_API virtual bool UnregisterWorldAssetStreaming(const FGuid& InWorldAssetStreamingGuid) override;
443
446
447private:
449 ENGINE_API virtual void Draw3D(const TArray<FWorldPartitionStreamingSource>& Sources) const override;
450 ENGINE_API virtual bool ContainsRuntimeHash(const FString& Name) const override;
451 ENGINE_API virtual bool IsStreaming3D() const override;
452 virtual bool GetShouldMergeStreamingSourceInfo() const override { return true; }
453
454 ENGINE_API void GetAlwaysLoadedStreamingCells(const FSpatialHashStreamingGrid& StreamingGrid, TSet<const UWorldPartitionRuntimeCell*>& Cells) const;
455 ENGINE_API const TMap<FName, const FSpatialHashStreamingGrid*>& GetNameToGridMapping() const;
456#if WITH_EDITOR
459#endif
460 ENGINE_API TArray<const FSpatialHashStreamingGrid*> GetFilteredStreamingGrids() const;
461
464 friend struct FSpatialHashSettings;
465 friend UE::Private::WorldPartition::FStreamingDescriptor;
466};
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#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
return true
Definition ExternalRpcRegistry.cpp:601
UE::Math::TVector2< double > FVector2D
Definition MathFwd.h:48
const bool
Definition NetworkReplayStreaming.h:178
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
#define UENUM(...)
Definition ObjectMacros.h:749
#define USTRUCT(...)
Definition ObjectMacros.h:746
#define GENERATED_USTRUCT_BODY(...)
Definition ObjectMacros.h:767
EWorldPartitionRuntimeCellVisualizeMode
Definition WorldPartitionRuntimeCell.h:33
EWorldPartitionStreamingPerformance
Definition WorldPartitionRuntimeHash.h:39
EWorldPartitionCVarProjectDefaultOverride
Definition WorldPartitionRuntimeSpatialHash.h:29
FInt64Vector3 FGridCellCoord
Definition WorldPartitionRuntimeSpatialHash.h:18
FInt64Vector2 FGridCellCoord2
Definition WorldPartitionRuntimeSpatialHash.h:19
EStreamingSourceTargetState
Definition WorldPartitionStreamingSource.h:218
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition WorldPartitionRuntimeSpatialHash.h:288
Definition Archive.h:1208
Definition IConsoleManager.h:2026
Definition NameTypes.h:617
Definition ObjectSaveContext.h:244
Definition UnrealType.h:3087
Definition WorldPartitionStreamingSource.h:11
Definition WorldPartitionDraw2DContext.h:117
Definition Array.h:670
Definition AssetRegistryState.h:50
Definition UnrealString.h.inl:34
Definition SubclassOf.h:30
Definition Class.h:3793
Definition HLODLayer.h:43
Definition WorldPartitionRuntimeHash.h:61
Definition WorldPartitionRuntimeSpatialHash.h:300
TArray< FSpatialHashStreamingGrid > StreamingGrids
Definition WorldPartitionRuntimeSpatialHash.h:309
Definition WorldPartitionRuntimeCell.h:236
Definition WorldPartitionRuntimeHashSet.h:151
Definition WorldPartitionRuntimeHash.h:192
Definition WorldPartitionRuntimeSpatialHash.h:314
Definition WorldPartitionStreamingPolicy.h:94
Definition WorldPartitionSubsystem.h:52
Definition WorldPartition.h:142
Definition World.h:918
Definition RuntimePartitionLHGrid.h:12
Definition Color.h:486
Definition Guid.h:109
Definition HierarchicalLogArchive.h:14
Definition Color.h:48
static CORE_API FLinearColor MakeRandomColor()
Definition Color.cpp:488
Definition UnrealType.h:6865
Definition SoftObjectPath.h:56
Definition WorldPartitionRuntimeSpatialHash.h:233
Definition WorldPartitionRuntimeSpatialHash.h:37
bool bUseAlignedGridLevels
Definition WorldPartitionRuntimeSpatialHash.h:55
friend bool operator!=(const FSpatialHashSettings &Lhs, const FSpatialHashSettings &Rhs)=default
void UpdateSettings(const UWorldPartitionRuntimeSpatialHash &RuntimeSpatialHash)
friend bool operator==(const FSpatialHashSettings &Lhs, const FSpatialHashSettings &Rhs)=default
bool bSnapNonAlignedGridLevelsToLowerLevels
Definition WorldPartitionRuntimeSpatialHash.h:58
Definition WorldPartitionRuntimeSpatialHash.h:71
Definition WorldPartitionRuntimeSpatialHash.h:96
Definition WorldPartitionRuntimeSpatialHash.h:132
FSpatialHashStreamingGrid(FSpatialHashStreamingGrid &&Other)=default
FSpatialHashStreamingGrid(const FSpatialHashStreamingGrid &Other)=delete
FSpatialHashStreamingGrid & operator=(FSpatialHashStreamingGrid &&Other)=default
FSpatialHashStreamingGrid & operator=(const FSpatialHashStreamingGrid &Other)=delete
Definition RuntimeSpatialHashGridHelper.h:27
FVector Origin
Definition RuntimeSpatialHashGridHelper.h:475
FBox WorldBounds
Definition RuntimeSpatialHashGridHelper.h:474
int64 CellSize
Definition RuntimeSpatialHashGridHelper.h:476
Definition WorldPartitionRuntimeHash.h:156
Definition WorldPartitionRuntimeSpatialHashGridPreviewer.h:14
Definition WorldPartitionRuntimeHash.h:166
Definition WorldPartitionStreamingSource.h:240
Definition WorldPartitionStreamingSource.h:344
Definition ObjectPtr.h:488
Definition StructOpsTypeTraits.h:11
@ WithCopy
Definition StructOpsTypeTraits.h:17
Definition StructOpsTypeTraits.h:46
Definition IntVector.h:670
Definition IntVector.h:22
static CORE_API const TVector2< double > ZeroVector
Definition Vector2D.h:63