UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
HLODHashBuilder.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if WITH_EDITOR
6
7#include "Math/MathFwd.h"
10#include "UObject/Class.h"
11
13class UTexture;
14class UStaticMesh;
15class USkinnedAsset;
16class UObject;
17
19{
20public:
22 void PushObjectContext(const class UObject* InObjectContext);
23
25 void PopObjectContext();
26
27 template <typename TParamType>
29 {
30 FArchive& Self = *this;
31 return Self << InValue;
32 }
33
34 // Numeric / enum values will be logged as string (order preserved)
35 template <typename T>
37 HashField(const T& InFieldValue, const FName& InFieldName)
38 {
40
42 }
43
44 // Everything else will log a CRC32 as 8-hex string
45 template <typename T>
47 HashField(const T& InFieldValue, const FName& InFieldName)
48 {
51
52 AddField(InFieldName, FString::Printf(TEXT("%08X"), FieldHashAr.GetCrc()));
53
55 }
56
57 void HashField(const FString& InFieldValue, const FName& InFieldName)
58 {
59 AddField(InFieldName, InFieldValue);
60
62 }
63
64 void HashField(const FName& InFieldValue, const FName& InFieldName)
65 {
66 AddField(InFieldName, InFieldValue.ToString());
67
69 }
70
72 {
73 AddField(InFieldName, InFieldValue);
74
75 FString StringValue(InFieldValue);
76 *this << StringValue;
77 }
78
80 {
81 AddField(InFieldName, InFieldValue);
82
83 FString StringValue(InFieldValue);
84 *this << StringValue;
85 }
86
88 {
90
92 }
93
94 template <typename T>
96 {
97 AddField(InFieldName, InFieldValue ? InFieldValue->GetPathName() : TEXT("<none>"));
98
100 }
101
107
108 //~ Begin FArchive Interface
109 ENGINE_API virtual FArchive& operator<<(UObject*& Object) override;
110 //~ End FArchive Interface
111
112 void LogContext(const TCHAR* Context, bool bOutputHash);
113
114 // For visibility of the overloads we don't override
115 using FArchiveCrc32::operator<<;
116
117 ENGINE_API FString BuildHashReport() const;
118
119private:
121
122 // Add a field to the current object context
123 void AddField(const FName& InFieldName, const FString& InFieldValue)
124 {
125 FFieldArray& Fields = ObjectContextStack.IsEmpty() ? GlobalFields : ObjectsHashes.FindOrAdd(ObjectContextStack.Top()).Fields;
126 Fields.Emplace(InFieldName, InFieldValue);
127 }
128
129 // Pretty enum string for UENUMs; falls back to the integer value if no UENUM is available.
130 template <typename T>
131 static FString EnumToPrettyString(T InEnumValue)
132 {
133 // non-null only for UENUMs
134 if (const UEnum* EnumType = StaticEnum<T>())
135 {
136 const int64 RawValue = static_cast<int64>(InEnumValue);
137 const FString Name = EnumType->GetNameStringByValue(RawValue);
138 if (!Name.IsEmpty())
139 {
140 return Name + TEXT("(") + LexToString(static_cast<__underlying_type(T)>(InEnumValue)) + TEXT(")");
141 }
142 }
143
144 // Fallback to the integer value
145 return LexToString(static_cast<__underlying_type(T)>(InEnumValue));
146 }
147
148 // Helper to stringify fields
149 template <typename T>
150 static FString FieldValueToString(const T& InFieldValue)
151 {
152 if constexpr (std::is_same<T, bool>::value)
153 {
154 return InFieldValue ? TEXT("1") : TEXT("0");
155 }
156 else if constexpr (TIsEnum<T>::Value)
157 {
159 }
160 else if constexpr (TIsFloatingPoint<T>::Value)
161 {
162 static const int32 Precision = 4;
163 FString S = FString::Printf(TEXT("%.*f"), Precision, InFieldValue);
164
165 while (S.Len() && S.EndsWith(TEXT("0")))
166 {
167 S.LeftChopInline(1);
168 }
169
170 if (S.Len() && S.EndsWith(TEXT(".")))
171 {
172 S.LeftChopInline(1);
173 }
174
175 return S.IsEmpty() ? TEXT("0") : S;
176 }
177 else if constexpr (TIsIntegral<T>::Value)
178 {
180 }
181 else
182 {
183 static_assert(!sizeof(T), "FieldValueToString only for numeric/enum types");
184 return FString();
185 }
186 }
187
188private:
189 // For a given asset, store its hash & type.
190 struct FAssetHash
191 {
192 uint32 Hash = 0;
193 FName AssetType = NAME_None;
194 };
196
197 // Array of name/value for fields.
199
200 // Track assets references & fields values for a given object.
201 struct FObjectHash
202 {
203 uint32 Hash = 0;
205 FFieldArray Fields;
206 };
207
208 // Map of objects names to their data.
210
211 // Stack of objects.
213
214 // Global hashing fields not tied to any particular object.
216};
217
218// Templated operator overloads for handling arrays
219template <typename TElementType, typename TAllocatorType>
221{
223 FArchive& Self = Ar;
224 return Self << ArrayMutable;
225}
226
227template <typename TElementType, typename TAllocatorType>
229{
230 FArchive& Self = Ar;
231 return Self << InArray;
232}
233
234class FHLODHashScope
235{
236public:
237 enum class EFlags : uint8
238 {
239 None = 0,
240 ResetHash = 1 << 0,
241 };
242
244 : Builder(InBuilder)
245 {
246 Builder.PushObjectContext(InObjectContext);
247
248 if (EnumHasAnyFlags(InFlags, EFlags::ResetHash))
249 {
250 Builder.Reset();
251 }
252 }
253
255 {
256 Builder.PopObjectContext();
257 }
258
259private:
260 FHLODHashBuilder& Builder;
261};
262
263#endif
return Self
Definition CocoaThread.cpp:337
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::WIDECHAR WIDECHAR
A wide character. Normally a signed type.
Definition Platform.h:1133
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::ANSICHAR ANSICHAR
An ANSI character. Normally a signed type.
Definition Platform.h:1131
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
constexpr bool EnumHasAnyFlags(Enum Flags, Enum Contains)
Definition EnumClassFlags.h:35
FArchive & operator<<(FArchive &Ar, FEnvQueryDebugProfileData::FStep &Data)
Definition EnvQueryTypes.cpp:489
const TCHAR * LexToString(EAnalyticsRecordEventMode Mode)
Definition IAnalyticsProvider.cpp:5
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition ArchiveCrc32.h:21
friend FArchiveCrc32 & operator<<(FArchiveCrc32 &Ar, const StructType &Value)
Definition ArchiveCrc32.h:49
Definition Archive.h:1208
Definition NameTypes.h:617
Definition Array.h:670
Definition EnableIf.h:20
Definition AssetRegistryState.h:50
Definition UnrealString.h.inl:34
Definition Class.h:2791
Definition MaterialInterface.h:296
Definition Object.h:95
Definition SkinnedAsset.h:47
Definition StaticMesh.h:593
Definition Texture.h:1219
CORE_API uint32 GetRoundedTransformCRC32(const FTransform &InTransform)
Definition TransformUtilities.cpp:9
Definition IsEnum.h:7
Definition IsFloatingPoint.h:12
Definition IsIntegral.h:12
Definition ObjectPtr.h:488