UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
InstancedSkinnedMeshComponent.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
12#include "InstancedSkinnedMeshComponent.generated.h"
13
17class UTexture;
18class UAnimBank;
21
22USTRUCT()
24{
26
27 UPROPERTY(EditAnywhere, Category=Instances)
29
30 UPROPERTY(EditAnywhere, Category = Animation)
31 uint32 AnimationIndex;
32
34 : Transform(FTransform3f::Identity)
35 , AnimationIndex(0)
36 {
37 }
38
44
46 {
47 Ar << InstanceData.Transform;
48 Ar << InstanceData.AnimationIndex;
49 return Ar;
50 }
51};
52
53UCLASS(ClassGroup=Rendering, hidecategories=(Object,Activation,Collision,"Components|Activation",Physics), editinlinenew, meta=(BlueprintSpawnableComponent), Blueprintable, MinimalAPI)
54UE_EXPERIMENTAL(5.6, "This class is currently extremely experimental and should not be used at this time.")
55class UInstancedSkinnedMeshComponent : public USkinnedMeshComponent
56{
58
60 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Animation)
61 TObjectPtr<class UTransformProviderData> TransformProvider;
62
64 UPROPERTY(EditAnywhere, SkipSerialization, DisplayName="Instances", Category=Instances, meta=(MakeEditWidget=true, EditFixedOrder))
66
68 UPROPERTY(EditAnywhere, Category=Instances, AdvancedDisplay)
69 int32 NumCustomDataFloats = 0;
70
75 UPROPERTY(EditAnywhere, EditFixedSize, SkipSerialization, DisplayName="Custom Data", Category=Instances, AdvancedDisplay, meta=(EditFixedOrder))
76 TArray<float> InstanceCustomData;
77
81 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Animation)
82 float AnimationMinScreenSize = 0.0f;
83
85 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Culling)
86 int32 InstanceMinDrawDistance;
87
89 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Culling)
90 int32 InstanceStartCullDistance;
91
93 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Culling)
94 int32 InstanceEndCullDistance;
95
97 UPROPERTY()
98 uint8 bInheritPerInstanceData : 1;
99
100 UPROPERTY()
101 FBox PrimitiveBoundsOverride;
102
103 UPROPERTY()
104 bool bIsInstanceDataGPUOnly = false;
105
106 UPROPERTY()
107 int32 NumInstancesGPUOnly = 0;
108
109public:
110
111 ENGINE_API UInstancedSkinnedMeshComponent(FVTableHelper& Helper);
112 virtual ~UInstancedSkinnedMeshComponent();
113
114 //~ Begin UObject Interface
117 virtual void BeginDestroy() override;
118#if WITH_EDITOR
119 virtual void PostEditChangeChainProperty(FPropertyChangedChainEvent& PropertyChangedEvent) override;
120 virtual void PostEditUndo() override;
121 virtual void BeginCacheForCookedPlatformData(const ITargetPlatform* TargetPlatform) override;
122 virtual bool IsCachedCookedPlatformDataLoaded( const ITargetPlatform* TargetPlatform ) override;
123#endif
124 //~ End UObject Interface
125
126 //~ Begin UActorComponent Interface
127 virtual void OnRegister() override;
128 virtual void SendRenderInstanceData_Concurrent() override;
129 virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
130 virtual bool IsHLODRelevant() const override;
131#if WITH_EDITOR
132 virtual void ComputeHLODHash(class FHLODHashBuilder& HashBuilder) const override;
133#endif
134 virtual void CreateRenderState_Concurrent(FRegisterComponentContext* Context) override;
135 virtual void DestroyRenderState_Concurrent() override;
136
137 virtual TStructOnScope<FActorComponentInstanceData> GetComponentInstanceData() const override;
138 //~ End UActorComponent Interface
139
140 //~ Begin USceneComponent Interface
141 virtual FBoxSphereBounds CalcBounds(const FTransform& LocalToWorld) const override;
142 virtual FPrimitiveSceneProxy* CreateSceneProxy() override;
143 virtual void OnUpdateTransform(EUpdateTransformFlags UpdateTransformFlags, ETeleportType Teleport) override;
144 //~ End USceneComponent Interface
145
146 //~ Begin USkinnedMeshComponent Interface
147 virtual const Nanite::FResources* GetNaniteResources() const;
148 virtual void RefreshBoneTransforms(FActorComponentTickFunction* TickFunction = nullptr) override;
149#if WITH_EDITOR
153 virtual void PostAssetCompilation();
154
155#endif
156 //~ End USkinnedMeshComponent Interface
157
158public:
160
161 bool UsesGPUOnlyInstances() const { return bIsInstanceDataGPUOnly; }
162
163 FBox GetPrimitiveBoundsOverride() const { return PrimitiveBoundsOverride; }
164 void SetPrimitiveBoundsOverride(const FBox& InBounds) { PrimitiveBoundsOverride = InBounds; }
165
167 UFUNCTION(BlueprintCallable, Category = "Components|InstancedSkinnedMesh")
168 ENGINE_API FPrimitiveInstanceId AddInstance(const FTransform& InstanceTransform, int32 AnimationIndex, bool bWorldSpace = false);
169
171 UFUNCTION(BlueprintCallable, Category = "Components|InstancedSkinnedMesh")
172 ENGINE_API TArray<FPrimitiveInstanceId> AddInstances(const TArray<FTransform>& Transforms, const TArray<int32>& AnimationIndices, bool bShouldReturnIds, bool bWorldSpace = false);
173
175 UFUNCTION(BlueprintCallable, Category = "Components|InstancedSkinnedMesh")
176 ENGINE_API bool SetCustomDataValue(FPrimitiveInstanceId InstanceId, int32 CustomDataIndex, float CustomDataValue);
177
179 ENGINE_API bool SetCustomData(FPrimitiveInstanceId InstanceId, TArrayView<const float> CustomDataFloats);
180
182 ENGINE_API bool GetCustomData(FPrimitiveInstanceId InstanceId, TArrayView<float> CustomDataFloats) const;
183
185 UFUNCTION(BlueprintCallable, Category = "Components|InstancedSkinnedMesh")
186 ENGINE_API void SetNumCustomDataFloats(int32 InNumCustomDataFloats);
187
189 UFUNCTION(BlueprintCallable, Category = "Components|InstancedSkinnedMesh")
190 ENGINE_API bool GetInstanceTransform(FPrimitiveInstanceId InstanceId, FTransform& OutInstanceTransform, bool bWorldSpace = false) const;
191
194
196 UFUNCTION(BlueprintCallable, Category = "Components|InstancedSkinnedMesh")
197 ENGINE_API bool RemoveInstance(FPrimitiveInstanceId InstanceId);
198
200 UFUNCTION(BlueprintCallable, Category = "Components|InstancedSkinnedMesh")
201 ENGINE_API void RemoveInstances(const TArray<FPrimitiveInstanceId>& InstancesToRemove);
202
204 UFUNCTION(BlueprintCallable, Category = "Components|InstancedSkinnedMesh")
205 ENGINE_API void ClearInstances();
206
207 UFUNCTION(BlueprintCallable, Category = "Components|InstancedSkinnedMesh")
209
210 UFUNCTION(BlueprintCallable, Category = "Components|InstancedSkinnedMesh")
212
218 UFUNCTION(BlueprintCallable, Category = "Components|InstancedSkinnedMesh")
220
221 ENGINE_API bool IsEnabled() const;
222 ENGINE_API int32 GetInstanceCount() const;
223
224 int32 GetNumCustomDataFloats() const { return NumCustomDataFloats; }
225 const TArray<float>& GetInstanceCustomData() const { return InstanceCustomData; }
226 const TArray<FSkinnedMeshInstanceData>& GetInstanceData() const { return InstanceData; }
227
228 int32 GetInstanceCountGPUOnly() const { return NumInstancesGPUOnly; }
229
230 int32 GetMinDrawDistance() const { return InstanceMinDrawDistance; }
231 void GetCullDistances(int32& OutStartCullDistance, int32& OutEndCullDistance) const { OutStartCullDistance = InstanceStartCullDistance; OutEndCullDistance = InstanceEndCullDistance; }
232 ENGINE_API void SetCullDistances(int32 StartCullDistance, int32 EndCullDistance);
233protected:
234
236 void PreApplyComponentInstanceData(struct FInstancedSkinnedMeshComponentInstanceData* ComponentInstanceData);
237
239 void ApplyComponentInstanceData(struct FInstancedSkinnedMeshComponentInstanceData* ComponentInstanceData);
240
242
243#if WITH_EDITOR
245 TBitArray<> SelectedInstances;
246#endif
247
248 bool bIsInstanceDataApplyCompleted = true;
249
250 void CreateHitProxyData(TArray<TRefCountPtr<HHitProxy>>& HitProxies);
251
254 FPrimitiveInstanceId AddInstanceInternal(int32 InstanceIndex, const FTransform& InstanceTransform, int32 AnimationIndex, bool bWorldSpace);
255
258 bool RemoveInstanceInternal(int32 InstanceIndex, bool InstanceAlreadyRemoved);
259
260private:
261 void ApplyInheritedPerInstanceData(const UInstancedSkinnedMeshComponent* InArchetype);
262 bool ShouldInheritPerInstanceData(const UInstancedSkinnedMeshComponent* InArchetype) const;
263 bool ShouldInheritPerInstanceData() const;
264
266
269
270 static ENGINE_API bool ShouldForceRefPose();
272
274 static ENGINE_API FPrimitiveSceneProxy* CreateSceneProxy(const FInstancedSkinnedMeshSceneProxyDesc& Desc, bool bHideSkin, bool bShouldNaniteSkin, bool bIsEnabled, int32 MinLODIndex);
275
276 TSharedPtr<FInstanceDataSceneProxy, ESPMode::ThreadSafe> GetOrCreateInstanceDataSceneProxy();
277
278 TSharedPtr<FInstanceDataSceneProxy, ESPMode::ThreadSafe> GetInstanceDataSceneProxy() const;
279
281
283
289
290private:
292
293public:
294 UE_DEPRECATED(5.7, "Method removed.")
296};
297
299USTRUCT()
301{
303
304public:
306
315
317
318 virtual bool ContainsData() const override
319 {
320 return true;
321 }
322
324 {
325 // 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.
326 CastChecked<UInstancedSkinnedMeshComponent>(Component)->PreApplyComponentInstanceData(this);
327 Super::ApplyToComponent(Component, CacheApplyPhase);
328 CastChecked<UInstancedSkinnedMeshComponent>(Component)->ApplyComponentInstanceData(this);
329 }
330
331 virtual void AddReferencedObjects(FReferenceCollector& Collector) override
332 {
333 Super::AddReferencedObjects(Collector);
334 Collector.AddReferencedObject(SkinnedAsset);
335 }
336
337public:
338 UPROPERTY()
339 TObjectPtr<USkinnedAsset> SkinnedAsset = nullptr;
340
341 UPROPERTY()
343
344 TBitArray<> SelectedInstances;
345
346 UPROPERTY()
347 bool bHasPerInstanceHitProxies = false;
348
349 UPROPERTY()
351
352 UPROPERTY()
354
355 UPROPERTY()
357};
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
EUpdateTransformFlags
Definition ActorComponent.h:95
ECacheApplyPhase
Definition ComponentInstanceDataCache.h:18
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
#define UE_EXPERIMENTAL(Version, Message)
Definition CoreMiscDefines.h:369
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
ELevelTick
Definition EngineBaseTypes.h:70
ETeleportType
Definition EngineTypes.h:2401
return true
Definition ExternalRpcRegistry.cpp:601
#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
EShaderPlatform
Definition RHIShaderPlatform.h:11
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 InstanceDataManager.h:68
Definition InstancedSkinnedMeshComponentHelper.h:13
Definition InstancedSkinnedMeshSceneProxy.h:87
Definition PrimitiveSceneProxy.h:296
Definition UObjectGlobals.h:2492
Definition ActorComponent.h:47
Definition SkeletalRenderPublic.h:85
Definition SkeletalMeshRenderData.h:17
Definition ObjectMacros.h:180
Definition ArrayView.h:139
Definition Array.h:670
Definition RefCounting.h:454
Definition SharedPointer.h:692
Definition StructOnScope.h:142
Definition ActorComponent.h:152
Definition AnimBank.h:178
Definition MaterialInterface.h:296
Definition SkinnedAsset.h:47
Definition SkinnedMeshComponent.h:258
Definition Texture.h:1219
Definition TransformProviderData.h:38
Type
Definition RHIFeatureLevel.h:20
ENGINE_API FBox CalcBounds(const FVector &P0, const FVector &P1, const FVector &P2, const FVector &P3)
Definition BezierUtilities.cpp:26
@ false
Definition radaudio_common.h:23
Definition EngineBaseTypes.h:571
Definition AnimBank.h:560
Definition InstanceDataManager.h:20
Definition InstancedSkinnedMeshComponent.h:301
virtual bool ContainsData() const override
Definition InstancedSkinnedMeshComponent.h:318
virtual void ApplyToComponent(UActorComponent *Component, const ECacheApplyPhase CacheApplyPhase) override
Definition InstancedSkinnedMeshComponent.h:323
virtual ~FInstancedSkinnedMeshComponentInstanceData()=default
virtual void AddReferencedObjects(FReferenceCollector &Collector) override
Definition InstancedSkinnedMeshComponent.h:331
FInstancedSkinnedMeshComponentInstanceData(const UInstancedSkinnedMeshComponent *InComponent)
Definition InstancedSkinnedMeshComponent.h:307
Definition InstancedSkinnedMeshSceneProxyDesc.h:11
Definition InstanceDataTypes.h:19
Definition PrimitiveSceneDesc.h:26
Definition PrimitiveSceneProxyDesc.h:12
Definition UnrealType.h:7001
Definition SceneComponent.h:1743
Definition AnimBank.h:356
bool bIsInstanceDataGPUOnly
Definition AnimBank.h:433
FBox PrimitiveBoundsOverride
Definition AnimBank.h:430
int32 NumInstancesGPUOnly
Definition AnimBank.h:436
Definition InstancedSkinnedMeshComponent.h:24
FSkinnedMeshInstanceData(const FTransform3f &InTransform, uint32 InAnimationIndex)
Definition InstancedSkinnedMeshComponent.h:39
friend FArchive & operator<<(FArchive &Ar, FSkinnedMeshInstanceData &InstanceData)
Definition InstancedSkinnedMeshComponent.h:45
Definition NaniteResources.h:410
Definition ObjectPtr.h:488
Definition BoxSphereBounds.h:25