UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MeshComponentHelper.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
8#include "MaterialDomain.h"
9#include "RHIFeatureLevel.h"
10
21
22template<class T>
24{
25 // Combine the material relevance for all materials.
26 FMaterialRelevance Result;
27 for (int32 ElementIndex = 0; ElementIndex < Component.GetNumMaterials(); ElementIndex++)
28 {
29 UMaterialInterface const* MaterialInterface = Component.GetMaterial(ElementIndex);
30 if (!MaterialInterface)
31 {
32 MaterialInterface = UMaterial::GetDefaultMaterial(MD_Surface);
33 }
34 Result |= MaterialInterface->GetRelevance_Concurrent(InShaderPlatform);
35 }
36
38 Component.GetMaterialSlotsOverlayMaterial(AssetAndComponentMaterialSlotsOverlayMaterial);
39 bool bAllMaterialSlotOverride = true;
41 {
42 if (MaterialInterface)
43 {
44 Result |= MaterialInterface->GetRelevance_Concurrent(InShaderPlatform);
45 }
46 else
47 {
49 }
50 }
51
52 //If all material slot set an overlay material we wont use the global one
54 {
55 UMaterialInterface const* OverlayMaterialInterface = Component.GetOverlayMaterial();
56 if (OverlayMaterialInterface != nullptr)
57 {
58 Result |= OverlayMaterialInterface->GetRelevance_Concurrent(InShaderPlatform);
59 }
60 }
61
62 return Result;
63}
64
65template<class T>
67{
68 //Add all the component override
69 OutMaterialSlotOverlayMaterials = Component.GetComponentMaterialSlotsOverlayMaterial();
70
71 //Get the asset material slot overlay material
73 Component.GetDefaultMaterialSlotsOverlayMaterial(AssetMaterialSlotOverlayMaterials);
74
75 //For each slot not override by the component set the asset slot value
76 for (int32 SlotIndex = 0; SlotIndex < AssetMaterialSlotOverlayMaterials.Num(); ++SlotIndex)
77 {
78 if (!OutMaterialSlotOverlayMaterials.IsValidIndex(SlotIndex))
79 {
81 }
82 //If the component did not already override this slot index put the asset value
83 if (!OutMaterialSlotOverlayMaterials[SlotIndex])
84 {
86 }
87 }
88}
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
Definition MeshComponentHelper.h:13
static FMaterialRelevance GetMaterialRelevance(const T &Component, EShaderPlatform InShaderPlatform)
Definition MeshComponentHelper.h:23
static void GetMaterialSlotsOverlayMaterial(const T &Component, TArray< TObjectPtr< UMaterialInterface > > &OutMaterialSlotOverlayMaterials)
Definition MeshComponentHelper.h:66
Definition Array.h:670
SizeType AddZeroed()
Definition Array.h:2755
Definition MaterialInterface.h:296
virtual class UMaterial * GetMaterial() PURE_VIRTUAL(UMaterialInterface
Definition MaterialInterface.h:482
ENGINE_API FMaterialRelevance GetRelevance_Concurrent(ERHIFeatureLevel::Type InFeatureLevel) const
Definition MaterialInterface.cpp:644
static ENGINE_API UMaterial * GetDefaultMaterial(EMaterialDomain Domain)
Definition Material.cpp:1071
Definition MaterialRelevance.h:13
Definition ObjectPtr.h:488