UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SkinnedMeshComponentHelper.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "ContentStreaming.h"
17
20{
21public:
22 template <typename T>
24
25 template <typename T>
27
28 template <typename T>
30
31 template <typename T>
32 static int32 GetNumLODs(const T& InComponent);
33
34 template <typename T>
35 static int32 ComputeMinLOD(const T& InComponent);
36
37 template <typename T>
38 static int32 GetValidMinLOD(const T& InComponent, const int32 InMinLODIndex);
39
40 template <typename T>
42
43 template <typename T>
44 static bool HasValidNaniteData(const T& InComponent);
45
46 template <typename T>
47 static bool ShouldNaniteSkin(const T& InComponent);
48
49 template <typename T>
51};
52
53template<class T>
55{
56 if (InComponent.GetMeshObject())
57 {
58 return &InComponent.GetMeshObject()->GetSkeletalMeshRenderData();
59 }
60 else if (InComponent.GetSkinnedAsset())
61 {
62 return InComponent.GetSkinnedAsset()->GetResourceForRendering();
63 }
64 else
65 {
66 return nullptr;
67 }
68}
69
70template<class T>
72{
73 int32 NumLODs = 0;
75 if (RenderData)
76 {
77 NumLODs = RenderData->LODRenderData.Num();
78 }
79 return NumLODs;
80}
81
82template<class T>
84{
85 const int32 AssetMinLOD = InComponent.GetSkinnedAsset()->GetMinLodIdx();
86 // overriden MinLOD can't be higher than asset MinLOD
87 int32 MinLODIndex = InComponent.bOverrideMinLod ? FMath::Max(InComponent.MinLodModel, AssetMinLOD) : AssetMinLOD;
89 return MinLODIndex;
90}
91
92template<class T>
94{
95 // Iterate the render data to validate that our min LOD has data that can be used.
98 const int32 FirstValidLODIndex = RenderData != nullptr ? RenderData->GetFirstValidLODIdx(InMinLODIndex) : INDEX_NONE;
99
100 // Return the first LOD that has render data that can be used.
104 return FMath::Clamp<int32>(FirstValidLODIndex, 0, MaxLODIndex);
105}
106
107template<class T>
109{
110 if (InComponent.OverrideMaterials.IsValidIndex(InMaterialIndex) && InComponent.OverrideMaterials[InMaterialIndex])
111 {
112 return InComponent.OverrideMaterials[InMaterialIndex];
113 }
114 else if (USkinnedAsset* SkinnedAsset = InComponent.GetSkinnedAsset())
115 {
116 if (!SkinnedAsset->IsCompiling() && SkinnedAsset->GetMaterials().IsValidIndex(InMaterialIndex) && SkinnedAsset->GetMaterials()[InMaterialIndex].MaterialInterface)
117 {
118 return SkinnedAsset->GetMaterials()[InMaterialIndex].MaterialInterface;
119 }
120 }
121
122 return nullptr;
123}
124
125template<class T>
127{
128 if (USkinnedAsset* SkinnedAsset = InComponent.GetSkinnedAsset())
129 {
130 // The max number of materials used is the max of the materials on the skeletal mesh and the materials on the mesh component
131 const int32 NumMaterials = FMath::Max(SkinnedAsset->GetMaterials().Num(), InComponent.OverrideMaterials.Num());
132 for (int32 MatIdx = 0; MatIdx < NumMaterials; ++MatIdx)
133 {
134 // GetMaterial will determine the correct material to use for this index.
135 UMaterialInterface* MaterialInterface = InComponent.GetMaterial(MatIdx);
136 OutMaterials.Add(MaterialInterface);
137 }
138
140 InComponent.GetMaterialSlotsOverlayMaterial(AssetAndComponentMaterialSlotsOverlayMaterial);
144 {
145 UMaterialInterface* OverlayMaterialInterface = InComponent.GetOverlayMaterial();
146 if (OverlayMaterialInterface != nullptr)
147 {
148 OutMaterials.Add(OverlayMaterialInterface);
149 }
150 }
151 }
152
154 {
155#if WITH_EDITOR
156 if (UPhysicsAsset* PhysicsAssetForDebug = InComponent.GetPhysicsAsset())
157 {
158 PhysicsAssetForDebug->GetUsedMaterials(OutMaterials);
159 }
160#endif
161 }
162}
163
164template<class T>
166{
167 OutMaterials.Reset();
168 if (USkinnedAsset* SkinnedAsset = InComponent.GetSkinnedAsset())
169 {
170 const TArray<FSkeletalMaterial>& SkeletalMaterials = SkinnedAsset->GetMaterials();
172 {
173 OutMaterials.Add(SkeletalMaterial.OverlayMaterialInterface);
174 }
175 }
176}
177
178template <typename T>
180{
181 if (InComponent.GetSkinnedAsset() && InComponent.GetSkinnedAsset()->GetResourceForRendering())
182 {
183 return InComponent.GetSkinnedAsset()->GetResourceForRendering()->NaniteResourcesPtr.Get();
184 }
185
186 return nullptr;
187}
188
189template <typename T>
191{
192 const Nanite::FResources* NaniteResources = GetNaniteResources(InComponent);
193 return NaniteResources != nullptr ? NaniteResources->PageStreamingStates.Num() > 0 : false;
194}
195
196template <typename T>
198{
199 const EShaderPlatform ShaderPlatform = InComponent.GetScene() ? InComponent.GetScene()->GetShaderPlatform() : GMaxRHIShaderPlatform;
201}
@ INDEX_NONE
Definition CoreMiscDefines.h:150
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
EShaderPlatform
Definition RHIShaderPlatform.h:11
EShaderPlatform GMaxRHIShaderPlatform
Definition RHI.cpp:1335
bool UseNanite(EShaderPlatform ShaderPlatform, bool bCheckForAtomicSupport, bool bCheckForProjectSetting)
Definition RenderUtils.cpp:1414
static void AppendAllOverlayMaterial(const TArray< TObjectPtr< UMaterialInterface > > &SourceMaterials, TArray< UMaterialInterface * > &OutMaterials, bool &bOutHaveNullEntry)
Definition MaterialOverlayHelper.h:15
Definition SkeletalMeshRenderData.h:17
Definition SkinnedMeshComponentHelper.h:20
static bool ShouldNaniteSkin(const T &InComponent)
Definition SkinnedMeshComponentHelper.h:197
static int32 ComputeMinLOD(const T &InComponent)
Definition SkinnedMeshComponentHelper.h:83
static FSkeletalMeshRenderData * GetSkeletalMeshRenderData(const T &InComponent)
Definition SkinnedMeshComponentHelper.h:54
static void GetDefaultMaterialSlotsOverlayMaterial(const T &InComponent, TArray< TObjectPtr< UMaterialInterface > > &OutMaterials)
Definition SkinnedMeshComponentHelper.h:165
static bool HasValidNaniteData(const T &InComponent)
Definition SkinnedMeshComponentHelper.h:190
static int32 GetNumLODs(const T &InComponent)
Definition SkinnedMeshComponentHelper.h:71
static const Nanite::FResources * GetNaniteResources(const T &InComponent)
Definition SkinnedMeshComponentHelper.h:179
static UMaterialInterface * GetMaterial(const T &InComponent, int32 InMaterialIndex)
Definition SkinnedMeshComponentHelper.h:108
static int32 GetValidMinLOD(const T &InComponent, const int32 InMinLODIndex)
Definition SkinnedMeshComponentHelper.h:93
static void GetUsedMaterials(const T &InComponent, TArray< UMaterialInterface * > &OutMaterials, bool bInGetDebugMaterials)
Definition SkinnedMeshComponentHelper.h:126
Definition Array.h:670
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
Definition MaterialInterface.h:296
virtual class UMaterial * GetMaterial() PURE_VIRTUAL(UMaterialInterface
Definition MaterialInterface.h:482
Definition PhysicsAsset.h:172
Definition SkinnedAsset.h:47
static ENGINE_API bool ShouldRenderNaniteSkinnedMeshes()
Definition SkinnedMeshComponent.cpp:134
Definition SkinnedAssetCommon.h:370
Definition NaniteResources.h:410
TArray< FPageStreamingState > PageStreamingStates
Definition NaniteResources.h:417
Definition ObjectPtr.h:488