UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DestructibleHLODComponent.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Containers/Map.h"
10#include "DestructibleHLODComponent.generated.h"
11
12
18
19// Entry for a damaged actor
20USTRUCT()
22{
24
25public:
26 static const uint8 MAX_HEALTH = 0xFF;
27
29 : ActorIndex(INDEX_NONE)
30 , ActorHealth(MAX_HEALTH)
31 {
32 }
33
35 : ActorIndex(InActorIndex)
36 , ActorHealth(MAX_HEALTH)
37 {
38 }
39
41 {
42 return ActorIndex == Other.ActorIndex && ActorHealth == Other.ActorHealth;
43 }
44
45 UPROPERTY()
46 int32 ActorIndex;
47
48 UPROPERTY()
49 uint8 ActorHealth;
50};
51
52
53// Replicated state of the destructible HLOD
54USTRUCT()
56{
58
59public:
61 {
62 return FFastArraySerializer::FastArrayDeltaSerialize<FWorldPartitionDestructibleHLODDamagedActorState, FWorldPartitionDestructibleHLODState>(DamagedActors, DeltaParms, *this);
63 }
64
66 void SetActorHealth(int32 InActorIndex, uint8 InActorHealth);
67
68 const bool IsClient() const { return bIsClient; }
69 const bool IsServer() const { return bIsServer; }
70
71 // ~ FFastArraySerializer Contract Begin
72 void PostReplicatedAdd(const TArrayView<int32>& AddedIndices, int32 FinalSize);
73 void PostReplicatedChange(const TArrayView<int32>& ChangedIndices, int32 FinalSize);
74 // ~ FFastArraySerializer Contract End
75
76private:
77 void ApplyDamagedActorState(int32 DamagedActorIndex);
78
79private:
80 UPROPERTY()
82
83 UPROPERTY(NotReplicated)
85
86 // Server only, map of actors indices to their damage info in the DamagedActors array
87 TArray<int32> ActorsToDamagedActorsMapping;
88
89 bool bIsServer = false;
90 bool bIsClient = false;
91 int32 NumDestructibleActors = 0;
92};
93
94
99
100
105USTRUCT()
107{
109
111 {
112 checkf((ComponentIndex & ~kComponentIndexMask) == 0, TEXT("ComponentIndex exceeds %u bits"), kComponentIndexBits);
113 checkf((InstanceCount & ~kItemCountMask) == 0, TEXT("InstanceCount exceeds %u bits"), kItemCountBits);
115 Mapping.A = ((ComponentIndex & kComponentIndexMask) << kComponentIndexShift) | (InstanceCount & kItemCountMask);
116 Mapping.B = InstanceStart; // full 32-bit Start
117 return Mapping;
118 }
119
121 {
122 ComponentIndex = (A >> kComponentIndexShift) & kComponentIndexMask;
123 OutInstanceCount = A & kItemCountMask;
125 }
126
127private:
128 UPROPERTY()
129 uint32 A = 0; // [ComponentIndex bits | InstanceCount bits]
130
131 UPROPERTY()
132 uint32 B = 0; // InstanceStart (32-bit)
133
134 static constexpr uint32 kComponentIndexBits = 11;
135 static constexpr uint32 kItemCountBits = 21;
136 static_assert(kComponentIndexBits + kItemCountBits == 32, "Bit count must total 32");
137
138 // --- Derived masks/shifts ---
139 static constexpr uint32 kComponentIndexShift = kItemCountBits;
140 static constexpr uint32 kComponentIndexMask = (1u << kComponentIndexBits) - 1u;
141 static constexpr uint32 kItemCountMask = (1u << kItemCountBits) - 1u;
142};
143
157USTRUCT()
159{
161
162 static FActorInstanceMappingsRef MakeMappingRange(uint32 RangeOffset, uint32 RangeCount)
163 {
164 checkf((RangeOffset & ~kRangeOffsetMask) == 0, TEXT("RangeOffset exceeds available storage"));
166 Mapping.A = (RangeOffset & kRangeOffsetMask);
167 Mapping.B = RangeCount;
168 return Mapping;
169 }
170
172 {
173 checkf((ComponentIndex & ~kComponentIndexMask) == 0, TEXT("ComponentIndex exceeds %u bits"), kComponentIndexBits);
174 checkf((InstanceCount & ~kItemCountMask) == 0, TEXT("InstanceCount exceeds %u bits"), kItemCountBits);
176 Mapping.A = kInlineTagMask
177 | ((ComponentIndex & kComponentIndexMask) << kComponentIndexShift)
178 | (InstanceCount & kItemCountMask);
179 Mapping.B = InstanceStart;
180 return Mapping;
181 }
182
183 bool IsInline() const
184 {
185 return (A & kInlineTagMask) != 0;
186 }
187
189 {
190 check(!IsInline());
191 OutRangeOffset = (A & kRangeOffsetMask);
193 }
194
196 {
197 check(IsInline());
198 OutComponentIndex = (A >> kComponentIndexShift) & kComponentIndexMask;
199 OutInstanceCount = A & kItemCountMask;
201 }
202
203private:
204 UPROPERTY()
205 uint32 A = 0; // [inline bit] + (inline ? [kComponentIndexBits + kItemCountBits] : [kOffsetBits]
206
207 UPROPERTY()
208 uint32 B = 0; // inline ? InstanceStart
209
210 // Storage bits
211 static constexpr uint32 kInlineFlagBits = 1;
212 static constexpr uint32 kRangeOffsetBits = 31;
213 static constexpr uint32 kComponentIndexBits = 10;
214 static constexpr uint32 kItemCountBits = 21;
215 static_assert(kInlineFlagBits + kComponentIndexBits + kItemCountBits == 32, "Bit count must total 32");
216 static_assert(kInlineFlagBits + kRangeOffsetBits == 32, "Bit count must total 32");
217
218 // Masks & shifts
219 static constexpr uint32 kInlineTagMask = (1u << kRangeOffsetBits);
220 static constexpr uint32 kRangeOffsetMask = (1u << kRangeOffsetBits) - 1u;
221 static constexpr uint32 kComponentIndexShift = kItemCountBits;
222 static constexpr uint32 kComponentIndexMask = (1u << kComponentIndexBits) - 1u;
223 static constexpr uint32 kItemCountMask = (1u << kItemCountBits) - 1u;
224};
225
226
227USTRUCT()
229{
231
232 // Array of HLOD ISMC. ComponentsMapping entries are indexing into it.
233 UPROPERTY()
235
236 // Compacted components mappings for each actors.
237 // Entries for a given actor are consecutive. Use PerActorMappingData to index into it.
238 UPROPERTY()
240
241 // For a given actor, either provides the range of entries for it in the ComponentsMapping array.
242 // OR
243 // If there's a single entry, it is found inline in the FActorInstanceMappingsRef struct.
244 UPROPERTY()
245 TMap<uint32, FActorInstanceMappingsRef> PerActorMappingData;
246
247 // Utility to iterate over all mapping entries for a given actor.
248 void ForEachActorInstancingMapping(uint32 InActorIndex, TFunctionRef<void(UHLODInstancedStaticMeshComponent*, uint32, uint32)> InFunc) const
249 {
250 if (const FActorInstanceMappingsRef* ActorMappingData = PerActorMappingData.Find(InActorIndex))
251 {
252 if (ActorMappingData->IsInline())
253 {
254 uint32 ComponentIndex, InstanceStart, InstanceCount;
255 ActorMappingData->GetInline(ComponentIndex, InstanceStart, InstanceCount);
256
257 InFunc(ISMCs[ComponentIndex], InstanceStart, InstanceCount);
258 }
259 else
260 {
261 uint32 RangeOffset, RangeCount;
262 ActorMappingData->GetComponentsMappingRange(RangeOffset, RangeCount);
263
264 for (uint32 i = 0; i < RangeCount; ++i)
265 {
266 const FComponentInstanceMapping& It = ComponentsMapping[RangeOffset + i];
267 uint32 ComponentIndex, InstanceStart, InstanceCount;
268 It.Decode(ComponentIndex, InstanceStart, InstanceCount);
269
270 InFunc(ISMCs[ComponentIndex], InstanceStart, InstanceCount);
271 }
272 }
273 }
274 }
275};
276
277
280{
282
283public:
284 ENGINE_API const TArray<FName>& GetDestructibleActors() const;
285 ENGINE_API void DestroyActor(int32 ActorIndex);
286 ENGINE_API void DamageActor(int32 ActorIndex, float DamagePercent);
287 ENGINE_API void ApplyDamagedActorState(int32 ActorIndex, const uint8 ActorHealth);
288 ENGINE_API void OnDestructionStateUpdated();
289
290#if WITH_EDITOR
294#endif
295
296private:
297 ENGINE_API virtual void BeginPlay() override;
298
299 void SetupVisibilityTexture();
300 void UpdateVisibilityTexture();
301
302private:
303 UPROPERTY()
304 TObjectPtr<UMaterialInterface> DestructibleHLODMaterial;
305
306 UPROPERTY()
307 FHLODInstancingPackedMappingData DestructibleHLODInstancesMappingData;
308
310 FWorldPartitionDestructibleHLODState DestructibleHLODState;
311
313 TObjectPtr<UMaterialInstanceDynamic> VisibilityMaterial;
314
316 TObjectPtr<UTexture2DDynamic> VisibilityTexture;
317
318 uint32 VisibilityTextureSize;
319
320 // Client only, visibility buffer that is meant to be sent to the GPU
321 TArray<uint8> VisibilityBuffer;
322
323 // Name of the destructible actors from the source cell.
324 UPROPERTY()
325 TArray<FName> DestructibleActors;
326};
327
328// Deprecated: Subclass
329UCLASS(Deprecated, MinimalAPI)
#define check(expr)
Definition AssertionMacros.h:314
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define TEXT(x)
Definition Platform.h:1272
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 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 USTRUCT(...)
Definition ObjectMacros.h:746
#define GENERATED_USTRUCT_BODY(...)
Definition ObjectMacros.h:767
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition TextureResource.h:250
Definition Sockets.Build.cs:6
Definition ArrayView.h:139
Definition Array.h:670
Definition AssetRegistryState.h:50
Definition UnrealString.h.inl:34
Definition DestructibleHLODComponent.h:331
Definition HLODInstancedStaticMeshComponent.h:14
Definition MaterialInstanceDynamic.h:15
Definition MaterialInterface.h:296
Definition Texture2DDynamic.h:35
Definition DestructibleHLODComponent.h:280
@ false
Definition radaudio_common.h:23
Definition DestructibleHLODComponent.h:159
void GetInline(uint32 &OutComponentIndex, uint32 &OutInstanceStart, uint32 &OutInstanceCount) const
Definition DestructibleHLODComponent.h:195
static FActorInstanceMappingsRef MakeMappingInline(uint32 ComponentIndex, uint32 InstanceStart, uint32 InstanceCount)
Definition DestructibleHLODComponent.h:171
void GetComponentsMappingRange(uint32 &OutRangeOffset, uint32 &OutRangeCount) const
Definition DestructibleHLODComponent.h:188
bool IsInline() const
Definition DestructibleHLODComponent.h:183
Definition DestructibleHLODComponent.h:107
void Decode(uint32 &ComponentIndex, uint32 &OutInstanceStart, uint32 &OutInstanceCount) const
Definition DestructibleHLODComponent.h:120
Definition FastArraySerializer.h:299
Definition FastArraySerializer.h:409
Definition DestructibleHLODComponent.h:229
Definition CoreNet.h:643
Definition DestructibleHLODComponent.h:22
FWorldPartitionDestructibleHLODDamagedActorState(int32 InActorIndex)
Definition DestructibleHLODComponent.h:34
FWorldPartitionDestructibleHLODDamagedActorState()
Definition DestructibleHLODComponent.h:28
Definition DestructibleHLODComponent.h:56
const bool IsClient() const
Definition DestructibleHLODComponent.h:68
const bool IsServer() const
Definition DestructibleHLODComponent.h:69
bool NetDeltaSerialize(FNetDeltaSerializeInfo &DeltaParms)
Definition DestructibleHLODComponent.h:60
Definition ObjectPtr.h:488
Definition StructOpsTypeTraits.h:11
Definition StructOpsTypeTraits.h:46