UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
InstancedStaticMeshComponent.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 "Stats/Stats.h"
8#include "EngineDefines.h"
9#include "HitProxies.h"
10#include "Misc/Guid.h"
16#include "StaticMeshResources.h"
17#include "InstancedStaticMeshComponent.generated.h"
18
22class FStaticLightingTextureMapping_InstancedStaticMesh;
23class ULightComponent;
28
30
31class FStaticLightingTextureMapping_InstancedStaticMesh;
32class FInstancedLightMap2D;
33class FInstancedShadowMap2D;
37
38USTRUCT()
40{
42
43 UPROPERTY(EditAnywhere, Category=Instances)
45
50
55
57 {
58 // @warning BulkSerialize: FInstancedStaticMeshInstanceData is serialized as memory dump
59 // See TArray::BulkSerialize for detailed description of implied limitations.
60 Ar << InstanceData.Transform;
61 return Ar;
62 }
63};
64
65USTRUCT()
67{
69
70 FStaticLightingTextureMapping_InstancedStaticMesh* Mapping;
71
73 : Mapping(nullptr)
74 {
75 }
76};
77
78USTRUCT()
80{
82
83 UPROPERTY()
84 int32 StartInstanceIndex = 0;
85
86 UPROPERTY()
87 int32 RandomSeed = 0;
88
90 {
91 Ar << InstanceData.StartInstanceIndex;
92 Ar << InstanceData.RandomSeed;
93 return Ar;
94 }
95};
96
97USTRUCT()
99{
101
103 : bIsValid(false)
104 , Hash(0)
106 {
107 }
108
110 {
111 bIsValid = false;
112 }
113
114 bool IsValid() const
115 {
116 return bIsValid;
117 }
118
120 {
121 bIsValid = true;
122 Value = InValue;
123 Hash = InHash;
124 }
125
126 const FBoxSphereBounds& GetValue(bool bCheckValid = true) const
127 {
128 ensure(!bCheckValid || bIsValid);
129 return Value;
130 }
131
132 bool operator == (uint32 InHash) const
133 {
134 return bIsValid && (Hash == InHash);
135 }
136
138 {
139 return !(*this == InHash);
140 }
141
142 static uint32 GetHash(const FTransform& InBoundTransform, const FBox& InInstanceBounds);
143
144private:
145 UPROPERTY()
146 bool bIsValid;
147
148 UPROPERTY()
149 uint32 Hash;
150
151 UPROPERTY()
153};
154
156UCLASS(ClassGroup = Rendering, meta = (BlueprintSpawnableComponent), Blueprintable, MinimalAPI)
158{
160
161
164
166 UPROPERTY(EditAnywhere, SkipSerialization, DisplayName="Instances", Category=Instances, meta=(MakeEditWidget=true, EditFixedOrder))
168
169 // TODO: KevinO cleanup
172 TArray<FMatrix> PerInstancePrevTransform;
173
176 FTransform PreviousComponentTransform;
177
179 UPROPERTY(EditAnywhere, Category=Instances, AdvancedDisplay)
181
185 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=InstancedStaticMeshComponent)
186 int32 InstancingRandomSeed=0;
187
192 UPROPERTY(EditAnywhere, EditFixedSize, SkipSerialization, DisplayName="Custom data", Category=Instances, AdvancedDisplay, meta=(EditFixedOrder))
193 TArray<float> PerInstanceSMCustomData;
194
196 UPROPERTY()
197 TArray<FInstancedStaticMeshRandomSeed> AdditionalRandomSeeds;
198
203 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Culling)
204 float InstanceLODDistanceScale = 1.f;
205
207 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Culling)
208 int32 InstanceMinDrawDistance;
209
211 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Culling)
212 int32 InstanceStartCullDistance;
213
215 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Culling)
216 int32 InstanceEndCullDistance;
217
219 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Culling)
220 uint8 bUseGpuLodSelection : 1;
221
223 UPROPERTY()
224 uint8 bInheritPerInstanceData : 1;
225
227 UPROPERTY()
228 uint8 bDisableCollision : 1;
229
234 uint8 bSupportRemoveAtSwap : 1;
235
236protected:
238
239private:
240 uint8 bHasPreviousTransforms : 1;
241
243 uint8 bUseConservativeBounds : 1;
244
246 uint8 bIsUpdatingBounds : 1;
247
248public:
250 UPROPERTY()
251 TArray<int32> InstanceReorderTable;
252
254 SIZE_T ProxySize;
255
257 inline int32 GetRenderIndex(int32 InInstanceIndex) const { return InstanceReorderTable.IsValidIndex(InInstanceIndex) ? InstanceReorderTable[InInstanceIndex] : InInstanceIndex; }
258
260 UFUNCTION(BlueprintCallable, Category="Components|InstancedStaticMesh")
261 ENGINE_API virtual int32 AddInstance(const FTransform& InstanceTransform, bool bWorldSpace = false);
262
264 UFUNCTION(BlueprintCallable, Category="Components|InstancedStaticMesh")
265 ENGINE_API virtual TArray<int32> AddInstances(const TArray<FTransform>& InstanceTransforms, bool bShouldReturnIndices, bool bWorldSpace = false, bool bUpdateNavigation = true);
266
268 UE_DEPRECATED(5.0, "Use AddInstance or AddInstances with bWorldSpace set to true.")
269 UFUNCTION(BlueprintCallable, Category = "Components|InstancedStaticMesh", meta=(DeprecatedFunction, DeprecationMessage="Use 'Add Instance' or 'Add Instances' with 'World Space' set to true."))
270 int32 AddInstanceWorldSpace(const FTransform& WorldTransform)
271 {
272 return AddInstance(WorldTransform, /*bWorldSpace*/true);
273 }
274
275 int32 GetNumInstances() const { return PerInstanceSMData.Num(); }
276
284 ENGINE_API TArray<FPrimitiveInstanceId> AddInstancesById(const TArrayView<const FTransform>& InstanceTransforms, bool bWorldSpace = false, bool bUpdateNavigation = true);
285 ENGINE_API FPrimitiveInstanceId AddInstanceById(const FTransform& InstanceTransforms, bool bWorldSpace = false);
288 ENGINE_API void SetCustomDataById(const TArrayView<const FPrimitiveInstanceId> &InstanceIds, TArrayView<const float> CustomDataFloats);
289 inline void SetCustomDataById(FPrimitiveInstanceId InstanceId, TArrayView<const float> CustomDataFloats) { SetCustomDataById(MakeArrayView(&InstanceId, 1), CustomDataFloats); }
290 ENGINE_API void SetCustomDataValueById(FPrimitiveInstanceId InstanceId, int32 CustomDataIndex, float CustomDataValue);
291
294 ENGINE_API virtual void RemoveInstancesById(const TArrayView<const FPrimitiveInstanceId> &InstanceIds, bool bUpdateNavigation = true);
295 inline void RemoveInstanceById(FPrimitiveInstanceId InstanceId) { RemoveInstancesById(MakeArrayView(&InstanceId, 1)); }
298 ENGINE_API void UpdateInstanceTransformById(FPrimitiveInstanceId InstanceId, const FTransform& NewInstanceTransform, bool bWorldSpace=false, bool bTeleport=false);
301 ENGINE_API void SetPreviousTransformById(FPrimitiveInstanceId InstanceId, const FTransform& NewPrevInstanceTransform, bool bWorldSpace=false);
304 ENGINE_API bool IsValidId(FPrimitiveInstanceId InstanceId);
305
307 inline int32 GetInstanceIndexForId(FPrimitiveInstanceId InstanceId) const { return PrimitiveInstanceDataManager.IdToIndex(InstanceId); }
308
309 ENGINE_API void SetHasPerInstancePrevTransforms(bool bInHasPreviousTransforms);
310
312 UFUNCTION(BlueprintCallable, Category = "Components|InstancedStaticMesh")
313 ENGINE_API virtual bool SetCustomDataValue(int32 InstanceIndex, int32 CustomDataIndex, float CustomDataValue, bool bMarkRenderStateDirty = false);
314
316 UFUNCTION(BlueprintCallable, Category = "Components|InstancedStaticMesh")
317 ENGINE_API virtual void SetNumCustomDataFloats(int32 InNumCustomDataFloats);
318
320 ENGINE_API virtual bool SetCustomData(int32 InstanceIndex, TArrayView<const float> CustomDataFloats, bool bMarkRenderStateDirty = false);
321 ENGINE_API virtual bool SetCustomData(int32 InstanceIndexStart, int32 InstanceIndexEnd, TConstArrayView<float> CustomDataFloats, bool bMarkRenderStateDirty = false);
322
324 ENGINE_API virtual void PreAllocateInstancesMemory(int32 AddedInstanceCount);
325
327 UFUNCTION(BlueprintCallable, Category = "Components|InstancedStaticMesh")
328 ENGINE_API bool GetInstanceTransform(int32 InstanceIndex, FTransform& OutInstanceTransform, bool bWorldSpace = false) const;
329
331 UFUNCTION(BlueprintCallable, Category = "Components|InstancedStaticMesh")
332 float GetLODDistanceScale() const { return InstanceLODDistanceScale; }
333
335 UFUNCTION(BlueprintCallable, Category = "Components|InstancedStaticMesh")
336 ENGINE_API void SetLODDistanceScale(float InLODDistanceScale);
337
338 // TODO: KevinO cleanup
340 ENGINE_API bool GetInstancePrevTransform(int32 InstanceIndex, FTransform& OutInstanceTransform, bool bWorldSpace = false) const;
341
344
346 ENGINE_API virtual float GetTextureStreamingTransformScale() const override;
348 ENGINE_API virtual bool GetMaterialStreamingData(int32 MaterialIndex, FPrimitiveMaterialInfo& MaterialData) const override;
350 ENGINE_API virtual bool BuildTextureStreamingDataImpl(ETextureStreamingBuildType BuildType, EMaterialQualityLevel::Type QualityLevel, ERHIFeatureLevel::Type FeatureLevel, TSet<FGuid>& DependentResources, bool& bOutSupportsBuildTextureStreamingData) override;
353
364 UFUNCTION(BlueprintCallable, Category = "Components|InstancedStaticMesh")
365 ENGINE_API virtual bool UpdateInstanceTransform(int32 InstanceIndex, const FTransform& NewInstanceTransform, bool bWorldSpace=false, bool bMarkRenderStateDirty=false, bool bTeleport=false);
366
377 UFUNCTION(BlueprintCallable, Category = "Components|InstancedStaticMesh")
378 ENGINE_API virtual bool BatchUpdateInstancesTransforms(int32 StartInstanceIndex, const TArray<FTransform>& NewInstancesTransforms, bool bWorldSpace=false, bool bMarkRenderStateDirty=false, bool bTeleport=false);
379
381 ENGINE_API virtual bool BatchUpdateInstancesTransforms(int32 StartInstanceIndex, TArrayView<const FTransform> NewInstancesTransforms, bool bWorldSpace = false, bool bMarkRenderStateDirty = false, bool bTeleport = false);
382
383 // TODO: KevinO cleanup
387 ENGINE_API virtual bool BatchUpdateInstancesTransforms(int32 StartInstanceIndex, const TArray<FTransform>& NewInstancesTransforms, const TArray<FTransform>& NewInstancesPrevTransforms, bool bWorldSpace = false, bool bMarkRenderStateDirty = false, bool bTeleport = false);
388
400 UFUNCTION(BlueprintCallable, Category = "Components|InstancedStaticMesh")
401 ENGINE_API virtual bool BatchUpdateInstancesTransform(int32 StartInstanceIndex, int32 NumInstances, const FTransform& NewInstancesTransform, bool bWorldSpace=false, bool bMarkRenderStateDirty=false, bool bTeleport=false);
402
403 ENGINE_API virtual bool BatchUpdateInstancesData(int32 StartInstanceIndex, int32 NumInstances, FInstancedStaticMeshInstanceData* StartInstanceData, bool bMarkRenderStateDirty = false, bool bTeleport = false);
404
406 UFUNCTION(BlueprintCallable, Category = "Components|InstancedStaticMesh")
407 ENGINE_API virtual bool RemoveInstance(int32 InstanceIndex);
408
410 UFUNCTION(BlueprintCallable, Category = "Components|InstancedStaticMesh")
411 ENGINE_API virtual bool RemoveInstances(const TArray<int32>& InstancesToRemove);
412
418
420 UFUNCTION(BlueprintCallable, Category="Components|InstancedStaticMesh")
421 ENGINE_API virtual void ClearInstances();
422
424 UFUNCTION(BlueprintCallable, Category = "Components|InstancedStaticMesh")
425 ENGINE_API int32 GetInstanceCount() const;
426
428 UFUNCTION(BlueprintCallable, Category = "Components|InstancedStaticMesh")
429 ENGINE_API bool IsValidInstance(int32 InstanceIndex) const;
430
432 UFUNCTION(BlueprintCallable, Category = "Components|InstancedStaticMesh")
433 ENGINE_API void SetCullDistances(int32 StartCullDistance, int32 EndCullDistance);
434
436 UFUNCTION(BlueprintCallable, Category = "Components|InstancedStaticMesh")
437 void GetCullDistances(int32& OutStartCullDistance, int32& OutEndCullDistance) const { OutStartCullDistance = InstanceStartCullDistance; OutEndCullDistance = InstanceEndCullDistance; }
438
440 UFUNCTION(BlueprintCallable, Category = "Components|InstancedStaticMesh")
441 ENGINE_API virtual TArray<int32> GetInstancesOverlappingSphere(const FVector& Center, float Radius, bool bSphereInWorldSpace=true) const;
442
444 UFUNCTION(BlueprintCallable, Category = "Components|InstancedStaticMesh")
445 ENGINE_API virtual TArray<int32> GetInstancesOverlappingBox(const FBox& Box, bool bBoxInWorldSpace=true) const;
446
447 ENGINE_API virtual bool ShouldCreatePhysicsState() const override;
448
450 ENGINE_API virtual void OnRegister() override;
451 ENGINE_API virtual void OnUnregister() override;
452
454 void SetRemoveSwap() { bSupportRemoveAtSwap = true; }
456 ENGINE_API virtual bool SupportsRemoveSwap() const;
457
463 void SetUseConservativeBounds(bool bValue) { bUseConservativeBounds = bValue; CachedConservativeInstanceBounds.Init(); }
464
465#if WITH_EDITOR
466 ENGINE_API virtual bool ComponentIsTouchingSelectionBox(const FBox& InSelBBox, const bool bConsiderOnlyBSP, const bool bMustEncompassEntireComponent) const override;
468
469 ENGINE_API virtual bool IsInstanceTouchingSelectionBox(int32 InstanceIndex, const FBox& InBox, const bool bMustEncompassEntireInstance) const;
471
472 ENGINE_API virtual bool CanEditChange(const FProperty* InProperty) const override;
473
474 ENGINE_API virtual void ComputeHLODHash(class FHLODHashBuilder& HashBuilder) const override;
475#endif
476
477 // Helper function to construct a base-set of instance data flags that in
478 ENGINE_API FInstanceDataFlags MakeInstanceDataFlags(bool bAnyMaterialHasPerInstanceRandom, bool bAnyMaterialHasPerInstanceCustomData) const;
479
480private:
482 FBox CachedConservativeInstanceBounds;
483
485 TArray<FBodyInstance*> AsyncDestroyPhysicsStatePayload;
486public:
487
488#if WITH_EDITOR
490 TBitArray<> SelectedInstances;
491
494
496 enum class EInstanceDeletionReason : uint8
497 {
501 Clearing
502 };
506 EInstanceDeletionReason DeletionState = EInstanceDeletionReason::NotDeleting;
507#endif
510
511 //~ Begin UActorComponent Interface
512 ENGINE_API virtual TStructOnScope<FActorComponentInstanceData> GetComponentInstanceData() const override;
513 ENGINE_API virtual void GetComponentChildElements(TArray<FTypedElementHandle>& OutElementHandles, const bool bAllowCreate = true) override;
514 ENGINE_API virtual bool IsHLODRelevant() const override;
515 ENGINE_API virtual void SendRenderInstanceData_Concurrent() override;
516 //~ End UActorComponent Interface
517
518 //~ Begin UPrimitiveComponent Interface
519 ENGINE_API virtual FPrimitiveSceneProxy* CreateSceneProxy() override;
520 ENGINE_API virtual FMatrix GetRenderMatrix() const override;
521 ENGINE_API virtual FBodyInstance* GetBodyInstance(FName BoneName = NAME_None, bool bGetWelded = true, int32 Index = INDEX_NONE) const override;
522 ENGINE_API virtual void RecreateInstanceBody(int32 InstanceBodyIndex) override;
523protected:
524 ENGINE_API virtual void OnCreatePhysicsState() override;
525 ENGINE_API virtual void OnDestroyPhysicsState() override;
526 ENGINE_API virtual bool OnAsyncDestroyPhysicsState(const UE::FTimeout& Timeout) override;
527 ENGINE_API virtual void OnAsyncDestroyPhysicsStateBegin_GameThread() override;
528
529public:
530 ENGINE_API virtual bool CanEditSimulatePhysics() override;
531
532 ENGINE_API virtual FBoxSphereBounds CalcBounds(const FTransform& BoundTransform) const override;
533 ENGINE_API virtual void UpdateBounds() override;
534
535 virtual bool SupportsStaticLighting() const override { return true; }
536#if WITH_EDITOR
538 ENGINE_API virtual FBox GetStreamingBounds() const override;
539#endif
540 ENGINE_API virtual void GetLightAndShadowMapMemoryUsage( int32& LightMapMemoryUsage, int32& ShadowMapMemoryUsage ) const override;
541
542 ENGINE_API virtual bool DoCustomNavigableGeometryExport(FNavigableGeometryExport& GeomExport) const override;
543
544 ENGINE_API virtual bool LineTraceComponent(FHitResult& OutHit, const FVector Start, const FVector End, const FCollisionQueryParams& Params) override;
545 ENGINE_API virtual bool SweepComponent(FHitResult& OutHit, const FVector Start, const FVector End, const FQuat& ShapRotation, const FCollisionShape& CollisionShape, bool bTraceComplex = false) override;
546 ENGINE_API virtual bool OverlapComponent(const FVector& Pos, const FQuat& Rot, const FCollisionShape& CollisionShape) const override;
547protected:
548 ENGINE_API virtual bool ComponentOverlapComponentImpl(class UPrimitiveComponent* PrimComp, const FVector Pos, const FQuat& Quat, const FCollisionQueryParams& Params) override;
549 ENGINE_API virtual bool ComponentOverlapMultiImpl(TArray<struct FOverlapResult>& OutOverlaps, const class UWorld* InWorld, const FVector& Pos, const FQuat& Rot, ECollisionChannel TestChannel, const struct FComponentQueryParams& Params, const struct FCollisionObjectQueryParams& ObjectQueryParams = FCollisionObjectQueryParams::DefaultObjectQueryParam) const override;
550 //~ End UPrimitiveComponent Interface
551
552 //~ Begin IPhysicsComponent Interface.
553public:
554 ENGINE_API virtual Chaos::FPhysicsObject* GetPhysicsObjectById(Chaos::FPhysicsObjectId Id) const override;
555 ENGINE_API virtual TArray<Chaos::FPhysicsObject*> GetAllPhysicsObjects() const override;
556 //~ End IPhysicsComponent Interface.
557
558 //~ Begin UStaticMeshComponentInterface
559protected:
560 ENGINE_API virtual FPrimitiveSceneProxy* CreateStaticMeshSceneProxy(Nanite::FMaterialAudit& NaniteMaterials, bool bCreateNanite) override;
561 //~ End UStaticMeshComponentInterface
562
563 //~ Begin UNavRelevantInterface Interface
564public:
565 ENGINE_API virtual void GetNavigationData(FNavigationRelevantData& Data) const override;
566 ENGINE_API virtual FBox GetNavigationBounds() const override;
567 ENGINE_API virtual bool IsNavigationRelevant() const override;
568 ENGINE_API virtual bool ShouldSkipDirtyAreaOnAddOrRemove() const override;
569 //~ End UNavRelevantInterface Interface
570
571 //~ Begin UObject Interface
572 ENGINE_API virtual void Serialize(FArchive& Ar) override;
573 ENGINE_API virtual void GetResourceSizeEx(FResourceSizeEx& CumulativeResourceSize) override;
574 ENGINE_API virtual void BeginDestroy() override;
575 ENGINE_API virtual void PreSave(FObjectPreSaveContext ObjectSaveContext) override;
576#if WITH_EDITOR
577 ENGINE_API virtual void PostStaticMeshCompilation() override;
578 ENGINE_API virtual void PostEditChangeChainProperty(FPropertyChangedChainEvent& PropertyChangedEvent) override;
579 ENGINE_API virtual void PostEditUndo() override;
583 ENGINE_API virtual void BeginCacheForCookedPlatformData( const ITargetPlatform* TargetPlatform ) override;
584
588 ENGINE_API virtual bool IsCachedCookedPlatformDataLoaded( const ITargetPlatform* TargetPlatform ) override;
589
590#endif
591 //~ End UObject Interface
592
599
601 ENGINE_API void PreApplyComponentInstanceData(struct FInstancedStaticMeshComponentInstanceData* ComponentInstanceData);
602
604 ENGINE_API virtual void ApplyComponentInstanceData(struct FInstancedStaticMeshComponentInstanceData* ComponentInstanceData);
605
607 ENGINE_API bool IsInstanceSelected(int32 InInstanceIndex) const;
608
610 ENGINE_API void SelectInstance(bool bInSelected, int32 InInstanceIndex, int32 InInstanceCount = 1);
611
613 ENGINE_API void ClearInstanceSelection();
614
616 ENGINE_API virtual void CollectPSOPrecacheData(const FPSOPrecacheParams& BasePrecachePSOParams, FMaterialInterfacePSOPrecacheParamsList& OutParams) override;
617
618 // Number of instances in the render-side instance buffer
619 virtual int32 GetNumRenderInstances() const { return PerInstanceSMData.Num(); }
620
621 ENGINE_API virtual void PropagateLightingScenarioChange() override;
622
623 ENGINE_API void GetInstancesMinMaxScale(FVector& MinScale, FVector& MaxScale) const;
624
625
626 UE_DEPRECATED(5.4, "This function has been added only for the purposes of moving LWI code outside of the engine. Don't use it, it will be removed soon.")
627 void OnPostPopulatePerInstanceData() { OnPostLoadPerInstanceData(); }
629 ENGINE_API virtual void PartialNavigationUpdate(int32 InstanceIdx);
630
632 ENGINE_API virtual void PartialNavigationUpdates(TConstArrayView<FTransform> InstanceTransforms);
633
635 ENGINE_API const TSharedPtr<FISMCInstanceDataSceneProxy, ESPMode::ThreadSafe>& GetInstanceDataSceneProxy() const;
636
640 ENGINE_API void SetBakedLightingDataChanged(int32 InInstanceIndex);
641
645 ENGINE_API void SetBakedLightingDataChangedAll();
646
652 ENGINE_API void InvalidateInstanceDataTracking();
653
654 // Deprecated in 5.7
656 {
657 return UPrimitiveComponent::GetUsedMaterialPropertyDesc(ShaderPlatform);
658 }
659
661 UE_DEPRECATED(5.7, "Please use GetUsedMaterialPropertyDesc with EShaderPlatform argument and not ERHIFeatureLevel::Type")
662 inline FPrimitiveMaterialPropertyDescriptor GetUsedMaterialPropertyDesc(ERHIFeatureLevel::Type FeatureLevel) const
663 {
664 return GetUsedMaterialPropertyDesc(GetFeatureLevelShaderPlatform(FeatureLevel));
665 }
666
667private:
668 ENGINE_API void ApplyInheritedPerInstanceData(const UInstancedStaticMeshComponent* InArchetype);
669 ENGINE_API bool ShouldInheritPerInstanceData(const UInstancedStaticMeshComponent* InArchetype) const;
670 ENGINE_API bool ShouldInheritPerInstanceData() const;
671
672 void PartialNavigateUpdateForCurrentInstances();
673
676
678 ENGINE_API void UpdateInstanceBodyTransform(int32 InstanceIndex, const FTransform& WorldSpaceInstanceTransform, bool bTeleport);
679
681 ENGINE_API bool BatchUpdateInstancesTransformsInternal(int32 StartInstanceIndex, TArrayView<const FTransform> NewInstancesTransforms, bool bWorldSpace, bool bMarkRenderStateDirty, bool bTeleport);
682
683protected:
684
686 UPROPERTY(Transient, DuplicateTransient, TextExportTransient)
687 int32 NumPendingLightmaps;
688
689 FPrimitiveInstanceDataManager PrimitiveInstanceDataManager;
690
691 void InvalidateCachedBounds();
692
693 ENGINE_API void CalcAndCacheNavigationBounds();
694
696 ENGINE_API void CreateAllInstanceBodies();
697
699 ENGINE_API void ClearAllInstanceBodies();
700
702 ENGINE_API virtual void FullNavigationUpdate();
703
705 {
706 Component,
708 Local,
709 Count,
710 Other
711 };
712
713 UE_DEPRECATED(5.5, "Use version with FBox")
714 FBoxSphereBounds CalcBoundsImpl(const FTransform& BoundTransform, bool bForNavigation) const;
715
721 FBoxSphereBounds CalcBoundsImpl(const FTransform& BoundTransform, const FBox& InstanceBounds) const;
722
724 virtual bool SupportsPartialNavigationUpdate() const { return true; }
725
727 ENGINE_API int32 AddInstanceInternal(int32 InstanceIndex, FInstancedStaticMeshInstanceData* InNewInstanceData, const FTransform& InstanceTransform, bool bWorldSpace);
728
730 ENGINE_API TArray<int32> AddInstancesInternal(TConstArrayView<FTransform> InstanceTransforms, bool bShouldReturnIndices, bool bWorldSpace, bool bUpdateNavigation = true);
731
733 ENGINE_API bool RemoveInstanceInternal(int32 InstanceIndex, bool InstanceAlreadyRemoved, bool bForceRemoveAtSwap = false, bool bUpdateNavigation = true);
734
740 FBox GetInstanceNavigationBounds() const;
741
743 ENGINE_API virtual void GetNavigationPerInstanceTransforms(const FBox& AreaBox, TArray<FTransform>& InstanceData) const;
744
747
749
751 UPROPERTY(Transient, DuplicateTransient, TextExportTransient)
753
754 ENGINE_API void ApplyLightMapping(FStaticLightingTextureMapping_InstancedStaticMesh* InMapping, const FStaticLightingBuildContext* LightingContext);
755
756 ENGINE_API void CreateHitProxyData(TArray<TRefCountPtr<HHitProxy>>& HitProxies);
757
759 ENGINE_API void BuildLegacyRenderData(FStaticMeshInstanceData& OutData);
761 ENGINE_API void SerializeRenderData(FArchive& Ar);
762
764 ENGINE_API virtual void OnPostLoadPerInstanceData();
765
766 // Helper to collect the base delta data from the ISM *notably not transforms*
767 ENGINE_API void BuildInstanceDataDeltaChangeSetCommon(FISMInstanceUpdateChangeSet &ChangeSet);
768
769 UE_DEPRECATED(5.7, "Please use BuildComponentInstanceData with EShaderPlatform argument and not ERHIFeatureLevel::Type")
770 ENGINE_API virtual void BuildComponentInstanceData(ERHIFeatureLevel::Type FeatureLevel, FInstanceUpdateComponentDesc& OutData);
771 ENGINE_API virtual void BuildComponentInstanceData(EShaderPlatform InShaderPlatform, FInstanceUpdateComponentDesc& OutData);
772
773 //~ ISMInstanceManager interface
774 ENGINE_API virtual bool CanEditSMInstance(const FSMInstanceId& InstanceId) const override;
775 ENGINE_API virtual bool CanMoveSMInstance(const FSMInstanceId& InstanceId, const ETypedElementWorldType InWorldType) const override;
776 ENGINE_API virtual bool GetSMInstanceTransform(const FSMInstanceId& InstanceId, FTransform& OutInstanceTransform, bool bWorldSpace = false) const override;
777 ENGINE_API virtual bool SetSMInstanceTransform(const FSMInstanceId& InstanceId, const FTransform& InstanceTransform, bool bWorldSpace = false, bool bMarkRenderStateDirty = false, bool bTeleport = false) override;
778 ENGINE_API virtual void NotifySMInstanceMovementStarted(const FSMInstanceId& InstanceId) override;
779 ENGINE_API virtual void NotifySMInstanceMovementOngoing(const FSMInstanceId& InstanceId) override;
780 ENGINE_API virtual void NotifySMInstanceMovementEnded(const FSMInstanceId& InstanceId) override;
781 ENGINE_API virtual void NotifySMInstanceSelectionChanged(const FSMInstanceId& InstanceId, const bool bIsSelected) override;
782 ENGINE_API virtual bool DeleteSMInstances(TArrayView<const FSMInstanceId> InstanceIds) override;
783 ENGINE_API virtual bool DuplicateSMInstances(TArrayView<const FSMInstanceId> InstanceIds, TArray<FSMInstanceId>& OutNewInstanceIds) override;
784
785 void InitializeInstancingRandomSeed(const bool bAllowRandomSeedValue = false);
786
787 friend FStaticLightingTextureMapping_InstancedStaticMesh;
788 friend FInstancedLightMap2D;
789 friend FInstancedShadowMap2D;
790
791#if STATS
793 TStatId StatId;
794#endif
795
796private:
797
799
800 UPROPERTY()
802
805 bool bNavigationCachedBoundsUpdated = false;
806};
807
821
823USTRUCT()
836
838USTRUCT()
840{
842public:
849
850 virtual bool ContainsData() const override
851 {
852 return true;
853 }
854
856 {
857 // The Super::ApplyToComponent will cause the scene proxy to be recreated, so we must do what we can to make sure the state is ok before that.
858 CastChecked<UInstancedStaticMeshComponent>(Component)->PreApplyComponentInstanceData(this);
859 Super::ApplyToComponent(Component, CacheApplyPhase);
860 CastChecked<UInstancedStaticMeshComponent>(Component)->ApplyComponentInstanceData(this);
861 }
862
863 virtual void AddReferencedObjects(FReferenceCollector& Collector) override
864 {
865 Super::AddReferencedObjects(Collector);
866 Collector.AddReferencedObject(StaticMesh);
867 }
868
869public:
871 UPROPERTY()
873
874 // Static lighting info
875 UPROPERTY()
877 UPROPERTY()
879
881 TBitArray<> SelectedInstances;
882
883 /* The cached random seed */
884 UPROPERTY()
885 int32 InstancingRandomSeed = 0;
886
887 /* Additional random seeds */
888 UPROPERTY()
890
891 UPROPERTY()
892 bool bHasPerInstanceHitProxies = false;
893};
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
EUpdateTransformFlags
Definition ActorComponent.h:95
constexpr auto MakeArrayView(OtherRangeType &&Other)
Definition ArrayView.h:873
#define ensure( InExpression)
Definition AssertionMacros.h:464
ECacheApplyPhase
Definition ComponentInstanceDataCache.h:18
@ INDEX_NONE
Definition CoreMiscDefines.h:150
@ ForceInit
Definition CoreMiscDefines.h:155
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define DECLARE_STATS_GROUP(GroupDesc, GroupId, GroupCat)
Definition Stats.h:689
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
ETeleportType
Definition EngineTypes.h:2401
ECollisionChannel
Definition EngineTypes.h:1088
return true
Definition ExternalRpcRegistry.cpp:601
@ HPP_World
Definition HitProxies.h:28
UE_FORCEINLINE_HINT bool operator!=(const FIndexedPointer &Other) const
Definition LockFreeList.h:76
const bool
Definition NetworkReplayStreaming.h:178
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#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
const bool bTraceComplex
Definition PhysicsInterfaceUtils.h:19
EShaderPlatform GetFeatureLevelShaderPlatform(const FStaticFeatureLevel InFeatureLevel)
Definition RHIGlobals.h:961
EShaderPlatform
Definition RHIShaderPlatform.h:11
ETextureStreamingBuildType
Definition TextureStreamingTypes.h:204
ETypedElementWorldType
Definition TypedElementWorldInterface.h:26
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition ISMInstanceUpdateChangeSet.h:13
Definition LightingBuildOptions.h:14
Definition NameTypes.h:617
Definition ObjectSaveContext.h:244
Definition ISMInstanceDataManager.h:45
Definition PrimitiveSceneProxy.h:296
Definition UnrealType.h:174
Definition UObjectGlobals.h:2492
Definition StaticMeshResources.h:1031
Definition TextureStreamingTypes.h:223
Definition ObjectMacros.h:180
Definition HitProxies.h:135
Definition SMInstanceManager.h:26
Definition ArrayView.h:139
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
UE_NODEBUG UE_FORCEINLINE_HINT bool IsValidIndex(SizeType Index) const
Definition Array.h:1122
Definition RefCounting.h:454
Definition SharedPointer.h:692
Definition StructOnScope.h:142
Definition ActorComponent.h:152
Definition BodySetup.h:128
Definition Timeout.h:21
Definition InstancedStaticMeshComponent.h:158
void SetUseConservativeBounds(bool bValue)
Definition InstancedStaticMeshComponent.h:463
FPrimitiveMaterialPropertyDescriptor GetUsedMaterialPropertyDesc(EShaderPlatform ShaderPlatform) const
Definition InstancedStaticMeshComponent.h:655
void SetCustomDataById(FPrimitiveInstanceId InstanceId, TArrayView< const float > CustomDataFloats)
Definition InstancedStaticMeshComponent.h:289
int32 GetInstanceIndexForId(FPrimitiveInstanceId InstanceId) const
Definition InstancedStaticMeshComponent.h:307
uint8 bIsInstanceDataApplyCompleted
Definition InstancedStaticMeshComponent.h:237
void RemoveInstanceById(FPrimitiveInstanceId InstanceId)
Definition InstancedStaticMeshComponent.h:295
virtual int32 GetNumRenderInstances() const
Definition InstancedStaticMeshComponent.h:619
virtual FVector GetTranslatedInstanceSpaceOrigin() const
Definition InstancedStaticMeshComponent.h:598
virtual bool SupportsStaticLighting() const override
Definition InstancedStaticMeshComponent.h:535
int32 GetNumInstances() const
Definition InstancedStaticMeshComponent.h:275
TArray< FBodyInstance * > InstanceBodies
Definition InstancedStaticMeshComponent.h:509
EBoundsCacheType
Definition InstancedStaticMeshComponent.h:705
Definition StaticMesh.h:593
Definition World.h:918
int32 FPhysicsObjectId
Definition PhysicsObject.h:20
Definition DebugViewModeHelpers.h:17
Type
Definition ICursor.h:18
Definition SceneComponent.h:24
@ false
Definition radaudio_common.h:23
U16 Index
Definition radfft.cpp:71
Definition PhysicsObjectInternal.h:16
Definition BodyInstance.h:320
Definition InstancedStaticMeshComponent.h:99
void Invalidate()
Definition InstancedStaticMeshComponent.h:109
void CacheValue(const FBoxSphereBounds &InValue, uint32 InHash=0)
Definition InstancedStaticMeshComponent.h:119
bool IsValid() const
Definition InstancedStaticMeshComponent.h:114
const FBoxSphereBounds & GetValue(bool bCheckValid=true) const
Definition InstancedStaticMeshComponent.h:126
Definition CollisionQueryParams.h:430
static ENGINE_API FCollisionObjectQueryParams DefaultObjectQueryParam
Definition CollisionQueryParams.h:538
Definition CollisionQueryParams.h:43
Definition CollisionShape.h:21
Definition CollisionQueryParams.h:297
Definition ConvexVolume.h:44
Definition Guid.h:109
Definition HitResult.h:21
Definition ISMInstanceDataManager.h:17
int32 NumCustomDataFloats
Definition ISMInstanceDataManager.h:29
Definition InstancedStaticMeshComponent.h:840
virtual void AddReferencedObjects(FReferenceCollector &Collector) override
Definition InstancedStaticMeshComponent.h:863
virtual bool ContainsData() const override
Definition InstancedStaticMeshComponent.h:850
virtual ~FInstancedStaticMeshComponentInstanceData()=default
FInstancedStaticMeshComponentInstanceData(const UInstancedStaticMeshComponent *InComponent)
Definition InstancedStaticMeshComponent.h:844
virtual void ApplyToComponent(UActorComponent *Component, const ECacheApplyPhase CacheApplyPhase) override
Definition InstancedStaticMeshComponent.h:855
Definition InstancedStaticMeshComponent.h:40
friend FArchive & operator<<(FArchive &Ar, FInstancedStaticMeshInstanceData &InstanceData)
Definition InstancedStaticMeshComponent.h:56
FInstancedStaticMeshInstanceData(const FMatrix &InTransform)
Definition InstancedStaticMeshComponent.h:51
Definition InstancedStaticMeshComponent.h:825
Definition InstancedStaticMeshComponent.h:67
Definition InstancedStaticMeshComponent.h:80
Definition NavigationSystemHelpers.h:25
Definition NavigationRelevantData.h:40
Definition PSOPrecache.h:30
Definition InstanceDataTypes.h:19
Definition TextureStreamingTypes.h:188
Definition SceneTypes.h:237
Definition UnrealType.h:7001
Definition ResourceSize.h:31
Definition SMInstanceElementId.h:20
Definition SceneComponent.h:1743
Definition StaticLighting.h:506
Definition TextureStreamingTypes.h:37
Definition TypedElementHandle.h:18
Definition InstancedStaticMeshComponent.h:810
int32 InstanceIndex
Definition InstancedStaticMeshComponent.h:812
HInstancedStaticMeshInstance(UInstancedStaticMeshComponent *InComponent, int32 InInstanceIndex)
Definition InstancedStaticMeshComponent.h:815
TObjectPtr< UInstancedStaticMeshComponent > Component
Definition InstancedStaticMeshComponent.h:811
Definition NaniteSceneProxy.h:66
Definition ObjectPtr.h:488
Definition LightweightStats.h:416
Definition BoxSphereBounds.h:25
static TVector< double > Zero()
Definition Vector.h:112
Definition InstanceDataTypes.h:36