UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
InstanceUpdateChangeSet.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
8
9class HHitProxy;
11
16{
17public:
19
22 inline bool IsEmpty() const { return NumItems == 0; }
23
26 inline bool IsDelta() const { return false; }
27
31 inline int32 GetNumItems() const { return NumItems; }
32
36 {
39
45
46 void operator++() { ++ItemIndex; }
47
51 int32 GetIndex() const { return ItemIndex; }
52
56 int32 GetItemIndex() const { return ItemIndex; }
57
58 explicit operator bool() const { return ItemIndex < MaxNum; }
59 };
60
62 {
63 return FConstIterator(0, NumItems);
64 }
65
66private:
67 int32 NumItems = 0;
68};
69
70template <typename ElementType, typename DeltaType>
72{
73 using FElement = ElementType;
75
79 bool bIsEnabled = true;
81
82
86 struct FWriter
87 {
89
91 {
92 if (!Setup.bIsEnabled)
93 {
94 return;
95 }
96
97 if (Setup.Delta.IsEmpty())
98 {
100 }
101 else
102 {
103 Setup.DeltaDataArray.Reset(Setup.Delta.GetNumItems());
104 for (auto It = Setup.Delta.GetIterator(); It; ++It)
105 {
106 check(Setup.DeltaDataArray.Num() < Setup.Delta.GetNumItems());
107 check(Setup.DeltaDataArray.Num() == It.GetItemIndex());
109 }
110 }
111 }
112
113 template <typename InElementType>
115 {
116 if (!Setup.bIsEnabled)
117 {
118 return;
119 }
120
121 if (Setup.Delta.IsEmpty())
122 {
124 }
125 // strides & element count matches - just copy the data
126 else
127 {
129 // It is a full update if either it is not a delta, or we're sending everything anyway
130 bool bIsFull = !Setup.Delta.IsDelta() || SourceData.Num() == Setup.Delta.GetNumItems() * Setup.ElementStride;
131
132 if (bIsFull)
133 {
134 // full update, bulk-copy
135 Setup.DeltaDataArray = SourceData;
136 }
137 else
138 {
140 for (auto It = Setup.Delta.GetIterator(); It; ++It)
141 {
143 Setup.DeltaDataArray.Append(&SourceData[It.GetIndex() * Setup.ElementStride], Setup.ElementStride);
144 }
145 }
146 }
147 }
148
150 {
151 if (!Setup.bIsEnabled)
152 {
153 return;
154 }
155
156 if (Setup.Delta.IsEmpty())
157 {
159 }
160 else
161 {
162 const int32 TotalNumItems = Setup.Delta.GetNumItems() * Setup.ElementStride;
163 bool bIsFull = !Setup.Delta.IsDelta();
164
165 if (bIsFull)
166 {
167 // full update, bulk initialization
169 }
170 else
171 {
173 for (auto It = Setup.Delta.GetIterator(); It; ++It)
174 {
176 for (int32 i = 0; i < Setup.ElementStride; ++i)
177 {
179 }
180 }
181 }
182 }
183 }
184 };
185
189 struct FReader
190 {
192
193 template <typename IndexRemapType>
195 {
196 static_assert(std::is_same_v<decltype(OutDataArray), decltype(Setup.DeltaDataArray)>, "The types should match or it won't be able to use MoveTemp properly");
197 if (!Setup.bIsEnabled)
198 {
199 OutDataArray.Reset();
200 }
201 else
202 {
204
205 bool bIsFull = !Setup.Delta.IsDelta() || Setup.NumInstances * Setup.ElementStride == Setup.DeltaDataArray.Num();;
206 if (bIsFull && IndexRemap.IsIdentity())
207 {
210 }
211 else
212 {
213 OutDataArray.SetNumUninitialized(Setup.NumInstances * Setup.ElementStride);
214 for (auto It = Setup.Delta.GetIterator(); It; ++It)
215 {
216 int32 ItemIndex = It.GetItemIndex();
217 int32 DestIndex = It.GetIndex();
218 IndexRemap.Remap(ItemIndex, DestIndex);
220 }
221 }
222 }
223 }
224
225 template <typename ElementTransformFuncType, typename IndexRemapType>
227 {
228 static_assert(std::is_same_v<decltype(OutDataArray), decltype(Setup.DeltaDataArray)>, "The types should match or it won't be able to use MoveTemp properly");
229 if (!Setup.bIsEnabled)
230 {
231 OutDataArray.Reset();
232 }
233 else
234 {
236 bool bIsFull = !Setup.Delta.IsDelta() || Setup.NumInstances * Setup.ElementStride == Setup.DeltaDataArray.Num();;
237 if (bIsFull && IndexRemap.IsIdentity())
238 {
240 // Just change ownership of the array
242 // Then apply transform in-place
243 for (int32 Index = 0; Index < Setup.NumInstances; ++Index)
244 {
246 }
247 }
248 else
249 {
251
252 OutDataArray.SetNumUninitialized(Setup.NumInstances);
253 for (auto It = Setup.Delta.GetIterator(); It; ++It)
254 {
255 int32 ItemIndex = It.GetItemIndex();
256 int32 DestIndex = It.GetIndex();
257 IndexRemap.Remap(ItemIndex, DestIndex);
258 ElementType Element = Setup.DeltaDataArray[ItemIndex];
259 ElementTransformFunc(Element);
260 OutDataArray[DestIndex] = Element;
261 }
262 }
263 }
264 }
265 };
266
268 {
269 check(!bIsEnabled || DeltaDataArray.Num() == Delta.GetNumItems() * ElementStride);
270 return FReader{ *this };
271 }
272
274 {
276 return FWriter{ *this };
277 }
278};
279
289
291
292
293
298{
299public:
310
320
321 template <FInstanceAttributeTracker::EFlag Flag>
330
335
340
341 template <FInstanceAttributeTracker::EFlag DeltaFlag, typename ElementType>
347
348 template <typename ElementType>
354
355 // These setups define the mapping from a delta attribute bit in the tracker to the data array.
356 // This is not a simple 1:1 mapping as we only track a few bits, and there is also special overrides to take into account.
360 // These use an identity delta, which means they send all or nothing.
363
364 // Convenience functions to get a reader / writer for a given array
365 auto GetTransformWriter() { return GetTransformSetup().GetWriter(); }
366 auto GetPrevTransformWriter() { return GetPrevTransformSetup().GetWriter(); }
367 auto GetCustomDataWriter() { return GetCustomDataSetup().GetWriter(); }
368 auto GetLocalBoundsWriter() { return GetLocalBoundsSetup().GetWriter(); }
369 auto GetSkinningDataWriter() { return GetSkinningDataSetup().GetWriter(); }
370
371 auto GetTransformReader() { return GetTransformSetup().GetReader(); }
372 auto GetPrevTransformReader() { return GetPrevTransformSetup().GetReader(); }
373 auto GetCustomDataReader() { return GetCustomDataSetup().GetReader(); }
374 auto GetLocalBoundsReader() { return GetLocalBoundsSetup().GetReader(); }
375 auto GetSkinningDataReader() { return GetSkinningDataSetup().GetReader(); }
376
378
379#if WITH_EDITOR
381 // Set editor data
382 void SetEditorData(const TArray<TRefCountPtr<HHitProxy>>& HitProxies, const TBitArray<> &SelectedInstances);
383#endif
384
389
390 bool IsFullUpdate() const
391 {
392 return bNeedFullUpdate;
393 }
394
396 bool bNeedFullUpdate = false;
397
403
409
410 // Needs its own bool because it is always present and thus doesn't have a flag in FInstanceDataFlags
412 bool bIdentityIdMap = false;
414
422
423#if WITH_EDITOR
425 TBitArray<> SelectedInstances;
427#endif
428
429 // Function that can generate all the random IDs on demand, if this is supplied is must generate all, otherwise it is zero-filled if they are requested.
431
435 float AbsMaxDisplacement = 0.0f;
438
445};
446
447
448#if WITH_EDITOR
449
451
452
453#endif
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define check(expr)
Definition AssertionMacros.h:314
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
const bool
Definition NetworkReplayStreaming.h:178
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition InstanceUpdateChangeSet.h:16
bool IsEmpty() const
Definition InstanceUpdateChangeSet.h:22
int32 GetNumItems() const
Definition InstanceUpdateChangeSet.h:31
FIdentityDeltaRange(int32 InNum)
Definition InstanceUpdateChangeSet.h:18
FConstIterator GetIterator() const
Definition InstanceUpdateChangeSet.h:61
bool IsDelta() const
Definition InstanceUpdateChangeSet.h:26
Definition InstanceAttributeTracker.h:416
Definition InstanceAttributeTracker.h:67
FDeltaRange< Flag > GetDeltaRange(bool bForceFullUpdate, int32 InNumItems) const
Definition InstanceAttributeTracker.h:530
Definition InstanceUpdateChangeSet.h:298
auto GetTransformReader()
Definition InstanceUpdateChangeSet.h:371
ENGINE_API void SetSharedLocalBounds(const FRenderBounds &Bounds)
Definition InstanceUpdateChangeSet.cpp:62
FVector PrimitiveWorldSpaceOffset
Definition InstanceUpdateChangeSet.h:433
TArray< FRenderTransform > PrevTransforms
Definition InstanceUpdateChangeSet.h:417
FInstanceDataFlags Flags
Definition InstanceUpdateChangeSet.h:402
FInstanceUpdateChangeSet(bool bInNeedFullUpdate, FInstanceAttributeTracker &&InInstanceAttributeTracker, int32 InNumSourceInstances)
Definition InstanceUpdateChangeSet.h:314
int32 MaxInstanceId
Definition InstanceUpdateChangeSet.h:437
auto GetCustomDataReader()
Definition InstanceUpdateChangeSet.h:373
TArray< FRenderTransform > Transforms
Definition InstanceUpdateChangeSet.h:416
auto GetLocalBoundsSetup()
Definition InstanceUpdateChangeSet.h:361
auto GetSkinningDataWriter()
Definition InstanceUpdateChangeSet.h:369
auto GetCustomDataWriter()
Definition InstanceUpdateChangeSet.h:367
FInstanceAttributeTracker::FDeltaRange< Flag > GetDelta(bool bForceEmpty, bool bForceFull=false) const
Definition InstanceUpdateChangeSet.h:322
auto GetTransformSetup()
Definition InstanceUpdateChangeSet.h:357
auto GetLocalBoundsWriter()
Definition InstanceUpdateChangeSet.h:368
auto GetLocalBoundsReader()
Definition InstanceUpdateChangeSet.h:374
int32 NumCustomDataFloats
Definition InstanceUpdateChangeSet.h:415
TFunction< void(TArray< float > &InstanceRandomIDs)> GeneratePerInstanceRandomIds
Definition InstanceUpdateChangeSet.h:430
bool bIdentityIdMap
Definition InstanceUpdateChangeSet.h:412
bool bNeedFullUpdate
Definition InstanceUpdateChangeSet.h:396
FInstanceAttributeTracker::FDeltaRange< FInstanceAttributeTracker::EFlag::TransformChanged > GetTransformDelta() const
Definition InstanceUpdateChangeSet.h:331
auto GetSkinningDataSetup()
Definition InstanceUpdateChangeSet.h:362
auto GetTransformWriter()
Definition InstanceUpdateChangeSet.h:365
auto GetPrevTransformWriter()
Definition InstanceUpdateChangeSet.h:366
TArray< FVector4f > InstanceLightShadowUVBias
Definition InstanceUpdateChangeSet.h:420
TArray< float > PerInstanceCustomData
Definition InstanceUpdateChangeSet.h:418
auto GetPrevTransformSetup()
Definition InstanceUpdateChangeSet.h:358
float AbsMaxDisplacement
Definition InstanceUpdateChangeSet.h:435
auto GetPrevTransformReader()
Definition InstanceUpdateChangeSet.h:372
auto GetCustomDataSetup()
Definition InstanceUpdateChangeSet.h:359
bool IsFullUpdate() const
Definition InstanceUpdateChangeSet.h:390
FInstanceUpdateChangeSet(int32 InNumSourceInstances, FInstanceDataFlags InFlags)
Definition InstanceUpdateChangeSet.h:303
int32 NumSourceInstances
Definition InstanceUpdateChangeSet.h:436
TOptional< FRenderTransform > PreviousPrimitiveToRelativeWorld
Definition InstanceUpdateChangeSet.h:434
TDeltaSetup< ElementType, FInstanceAttributeTracker::FDeltaRange< DeltaFlag > > GetSetup(bool bEnabledFlag, bool bForceFullFlag, TArray< ElementType > &DataArray, int32 ElementStride=1)
Definition InstanceUpdateChangeSet.h:342
FRenderTransform PrimitiveToRelativeWorld
Definition InstanceUpdateChangeSet.h:432
TArray< FPrimitiveInstanceId > IndexToIdMapDeltaData
Definition InstanceUpdateChangeSet.h:413
auto GetLightShadowUVBiasReader()
Definition InstanceUpdateChangeSet.h:377
FInstanceAttributeTracker::FDeltaRange< FInstanceAttributeTracker::EFlag::IndexChanged > GetIndexChangedDelta() const
Definition InstanceUpdateChangeSet.h:336
bool bUpdateAllInstanceTransforms
Definition InstanceUpdateChangeSet.h:411
FInstanceDataFlags ForceFullFlags
Definition InstanceUpdateChangeSet.h:408
auto GetSkinningDataReader()
Definition InstanceUpdateChangeSet.h:375
FInstanceAttributeTracker InstanceAttributeTracker
Definition InstanceUpdateChangeSet.h:395
TArray< FRenderBounds > InstanceLocalBounds
Definition InstanceUpdateChangeSet.h:421
TArray< uint32 > InstanceSkinningData
Definition InstanceUpdateChangeSet.h:419
TDeltaSetup< ElementType, FIdentityDeltaRange > GetSetup(bool bEnabledFlag, TArray< ElementType > &DataArray, int32 ElementStride=1)
Definition InstanceUpdateChangeSet.h:349
FPrecomputedInstanceSpatialHashDataPtr PrecomputedOptimizationData
Definition InstanceUpdateChangeSet.h:444
Definition InstanceUpdateChangeSet.h:284
TArray< int32 > ProxyIndexToComponentIndexRemap
Definition InstanceUpdateChangeSet.h:287
TArray< FInstanceSceneDataBuffers::FCompressedSpatialHashItem > Hashes
Definition InstanceUpdateChangeSet.h:286
Definition HitProxies.h:135
Definition ArrayView.h:139
UE_FORCEINLINE_HINT constexpr SizeType Num() const
Definition ArrayView.h:380
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void Reset(SizeType NewSize=0)
Definition Array.h:2246
UE_REWRITE bool IsEmpty() const
Definition Array.h:1133
UE_FORCEINLINE_HINT SizeType Emplace(ArgsType &&... Args)
Definition Array.h:2561
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
void Init(const ElementType &Element, SizeType Number)
Definition Array.h:3043
void Append(const TArray< OtherElementType, OtherAllocatorType > &Source)
Definition Array.h:2412
Definition AssetRegistryState.h:50
Definition AndroidPlatformMisc.h:14
Definition RefCounting.h:454
U16 Index
Definition radfft.cpp:71
Definition InstanceUpdateChangeSet.h:36
int32 MaxNum
Definition InstanceUpdateChangeSet.h:38
FConstIterator(int32 InIndex, int32 InMaxNum)
Definition InstanceUpdateChangeSet.h:40
int32 GetItemIndex() const
Definition InstanceUpdateChangeSet.h:56
void operator++()
Definition InstanceUpdateChangeSet.h:46
int32 ItemIndex
Definition InstanceUpdateChangeSet.h:37
int32 GetIndex() const
Definition InstanceUpdateChangeSet.h:51
static UE_FORCEINLINE_HINT void * Memcpy(void *Dest, const void *Src, SIZE_T Count)
Definition UnrealMemory.h:160
Definition RenderTransform.h:272
Definition RenderTransform.h:23
Definition InstanceUpdateChangeSet.h:190
void Scatter(TArray< ElementType > &OutDataArray, const IndexRemapType &IndexRemap)
Definition InstanceUpdateChangeSet.h:194
TDeltaSetup Setup
Definition InstanceUpdateChangeSet.h:191
void Scatter(TArray< ElementType > &OutDataArray, ElementTransformFuncType ElementTransformFunc, const IndexRemapType &IndexRemap)
Definition InstanceUpdateChangeSet.h:226
Definition InstanceUpdateChangeSet.h:87
void Gather(const TArrayView< InElementType > SourceData, int32 InElementStride=1)
Definition InstanceUpdateChangeSet.h:114
void Gather(const FElement &SingleSourceElement)
Definition InstanceUpdateChangeSet.h:149
void Gather(TFunctionRef< FElement(int32)> DataSourceFunc)
Definition InstanceUpdateChangeSet.h:90
TDeltaSetup Setup
Definition InstanceUpdateChangeSet.h:88
Definition InstanceUpdateChangeSet.h:72
ElementType FElement
Definition InstanceUpdateChangeSet.h:73
bool bIsEnabled
Definition InstanceUpdateChangeSet.h:79
FDelta Delta
Definition InstanceUpdateChangeSet.h:77
FWriter GetWriter()
Definition InstanceUpdateChangeSet.h:273
TArray< FElement > & DeltaDataArray
Definition InstanceUpdateChangeSet.h:76
int32 NumInstances
Definition InstanceUpdateChangeSet.h:80
FReader GetReader()
Definition InstanceUpdateChangeSet.h:267
DeltaType FDelta
Definition InstanceUpdateChangeSet.h:74
int32 ElementStride
Definition InstanceUpdateChangeSet.h:78
Definition Optional.h:131
Definition PimplPtr.h:50
Definition InstanceDataTypes.h:36
uint16 bHasPerInstanceDynamicData
Definition InstanceDataTypes.h:42
uint16 bHasPerInstanceLocalBounds
Definition InstanceDataTypes.h:45
uint16 bHasPerInstanceLMSMUVBias
Definition InstanceDataTypes.h:44
uint16 bHasPerInstanceCustomData
Definition InstanceDataTypes.h:41
uint16 bHasPerInstanceEditorData
Definition InstanceDataTypes.h:49
uint16 bHasPerInstanceSkinningData
Definition InstanceDataTypes.h:43