UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MaterialInstanceDynamic.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"
8#include "MaterialInstanceDynamic.generated.h"
9
10class UTexture;
12
13UCLASS(hidecategories=Object, collapsecategories, BlueprintType, MinimalAPI)
15{
17
18#if WITH_EDITOR
19 ENGINE_API virtual void UpdateCachedData() override;
20#endif
21
23 UFUNCTION(BlueprintCallable, meta=(Keywords = "SetFloatParameterValue"), Category="Rendering|Material")
24 ENGINE_API void SetScalarParameterValue(FName ParameterName, float Value);
25
27 UFUNCTION(BlueprintCallable, meta = (Keywords = "SetFloatParameterValue"), Category = "Rendering|Material")
28 ENGINE_API void SetScalarParameterValueByInfo(const FMaterialParameterInfo& ParameterInfo, float Value);
29
30 //~ NOTE: These Index-related functions should be used VERY carefully, and only in cases where optimization is
31 //~ critical. Generally that's only if you're using an unusually high number of parameters in a material AND
32 //~ setting a huge number of parameters in the same frame.
33
34 // Use this function to set an initial value and fetch the index for use in SetScalarParameterByIndex. This
35 // function should only be called once for a particular name, and then use SetScalarParameterByIndex for subsequent
36 // calls. However, beware using this except in cases where optimization is critical, which is generally only if
37 // you're using an unusually high number of parameters in a material and setting a large number of parameters in the
38 // same frame. Also, if the material is changed in any way that can change the parameter list, the index can be
39 // invalidated.
40 UFUNCTION(BlueprintCallable, meta = (Keywords = "SetFloatParameterValue"), Category = "Rendering|Material")
41 ENGINE_API bool InitializeScalarParameterAndGetIndex(const FName& ParameterName, float Value, int32& OutParameterIndex);
42
43 // Use the cached value of OutParameterIndex from InitializeScalarParameterAndGetIndex to set the scalar parameter
44 // ONLY on the exact same MID. Do NOT presume the index can be used from one instance on another. Only use this
45 // pair of functions when optimization is critical; otherwise use either SetScalarParameterValueByInfo or
46 // SetScalarParameterValue.
47 UFUNCTION(BlueprintCallable, meta = (Keywords = "SetFloatParameterValue"), Category = "Rendering|Material")
48 ENGINE_API bool SetScalarParameterByIndex(int32 ParameterIndex, float Value);
49
50 // Use this function to set an initial value and fetch the index for use in the following function.
51 ENGINE_API bool InitializeVectorParameterAndGetIndex(const FName& ParameterName, const FLinearColor& Value, int32& OutParameterIndex);
52 // Use the cached value of OutParameterIndex above to set the vector parameter ONLY on the exact same MID
53 ENGINE_API bool SetVectorParameterByIndex(int32 ParameterIndex, const FLinearColor& Value);
54
56 UFUNCTION(BlueprintCallable, meta=(DisplayName = "Get Scalar Parameter Value", ScriptName = "GetScalarParameterValue", Keywords = "GetFloatParameterValue"), Category="Rendering|Material")
57 ENGINE_API float K2_GetScalarParameterValue(FName ParameterName);
58
60 UFUNCTION(BlueprintCallable, meta = (DisplayName = "Get Scalar Parameter Value By Info", ScriptName = "GetScalarParameterValueByInfo", Keywords = "GetFloatParameterValue"), Category = "Rendering|Material")
61 ENGINE_API float K2_GetScalarParameterValueByInfo(const FMaterialParameterInfo& ParameterInfo);
62
64 UFUNCTION(BlueprintCallable, Category="Rendering|Material")
65 ENGINE_API void SetTextureParameterValue(FName ParameterName, class UTexture* Value);
66
68 UFUNCTION(BlueprintCallable, Category = "Rendering|Material")
69 ENGINE_API void SetTextureParameterValueByInfo(const FMaterialParameterInfo& ParameterInfo, class UTexture* Value);
70
72 UFUNCTION(BlueprintCallable, Category = "Rendering|Material")
73 ENGINE_API void SetRuntimeVirtualTextureParameterValue(FName ParameterName, class URuntimeVirtualTexture* Value);
74
76 UFUNCTION(BlueprintCallable, Category = "Rendering|Material")
77 ENGINE_API void SetRuntimeVirtualTextureParameterValueByInfo(const FMaterialParameterInfo& ParameterInfo, class URuntimeVirtualTexture* Value);
78
80 UFUNCTION(BlueprintCallable, Category = "Rendering|Material")
81 ENGINE_API void SetSparseVolumeTextureParameterValue(FName ParameterName, class USparseVolumeTexture* Value);
82
84 UFUNCTION(BlueprintCallable, meta=(DisplayName = "Get Texture Parameter Value", ScriptName = "GetTextureParameterValue"), Category="Rendering|Material")
85 ENGINE_API class UTexture* K2_GetTextureParameterValue(FName ParameterName);
86
88 UFUNCTION(BlueprintCallable, meta = (DisplayName = "Get Texture Parameter Value By Info", ScriptName = "GetTextureParameterValueByInfo"), Category = "Rendering|Material")
89 ENGINE_API class UTexture* K2_GetTextureParameterValueByInfo(const FMaterialParameterInfo& ParameterInfo);
90
92 UFUNCTION(BlueprintCallable, Category="Rendering|Material")
93 ENGINE_API void SetTextureCollectionParameterValue(FName ParameterName, UTextureCollection* Value);
94
96 UFUNCTION(BlueprintCallable, Category = "Rendering|Material")
97 ENGINE_API void SetTextureCollectionParameterValueByInfo(const FMaterialParameterInfo& ParameterInfo, UTextureCollection* Value);
98
100 UFUNCTION(BlueprintCallable, meta = (DisplayName = "Get Texture Collection Parameter Value By Info", ScriptName = "GetTextureCollectionParameterValueByInfo"), Category = "Rendering|Material")
101 ENGINE_API UTextureCollection* K2_GetTextureCollectionParameterValueByInfo(const FMaterialParameterInfo& ParameterInfo);
102
104 UFUNCTION(BlueprintCallable, meta=(DisplayName = "Get Texture Collection Parameter Value", ScriptName = "GetTextureCollectionParameterValue"), Category="Rendering|Material")
105 ENGINE_API UTextureCollection* K2_GetTextureCollectionParameterValue(FName ParameterName);
106
108 UFUNCTION(BlueprintCallable, meta=(Keywords = "SetColorParameterValue"), Category="Rendering|Material")
109 ENGINE_API void SetVectorParameterValue(FName ParameterName, FLinearColor Value);
110
111 // Conveniences to keep general FLinearColor constructors explicit without adding extra burden to existing users of this function (where the conversion is straightforward).
112 inline void SetVectorParameterValue(FName ParameterName, const FVector& Value) { SetVectorParameterValue(ParameterName, FLinearColor(Value)); }
113 inline void SetVectorParameterValue(FName ParameterName, const FVector4& Value) { SetVectorParameterValue(ParameterName, FLinearColor(Value)); }
114
116 UFUNCTION(BlueprintCallable, meta = (Keywords = "SetVectorParameterValue"), Category = "Rendering|Material")
117 ENGINE_API void SetDoubleVectorParameterValue(FName ParameterName, FVector4 Value);
118
120 UFUNCTION(BlueprintCallable, meta = (Keywords = "SetColorParameterValue"), Category = "Rendering|Material")
121 ENGINE_API void SetVectorParameterValueByInfo(const FMaterialParameterInfo& ParameterInfo, FLinearColor Value);
122
123 inline void SetVectorParameterValueByInfo(const FMaterialParameterInfo& ParameterInfo, const FVector& Value) { SetVectorParameterValueByInfo(ParameterInfo, FLinearColor(Value)); }
124 inline void SetVectorParameterValueByInfo(const FMaterialParameterInfo& ParameterInfo, const FVector4& Value) { SetVectorParameterValueByInfo(ParameterInfo, FLinearColor(Value)); }
125
127 UFUNCTION(BlueprintCallable, meta=(DisplayName = "Get Vector Parameter Value", ScriptName = "GetVectorParameterValue", Keywords = "GetColorParameterValue"), Category="Rendering|Material")
128 ENGINE_API FLinearColor K2_GetVectorParameterValue(FName ParameterName);
129
131 UFUNCTION(BlueprintCallable, meta = (DisplayName = "Get VectorParameter Value By Info", ScriptName = "GetVectorParameterValueByInfo", Keywords = "GetColorParameterValue"), Category = "Rendering|Material")
132 ENGINE_API FLinearColor K2_GetVectorParameterValueByInfo(const FMaterialParameterInfo& ParameterInfo);
133
143 UFUNCTION(BlueprintCallable, meta=(DisplayName = "Interpolate Material Instance Parameters", ScriptName = "InterpolateMaterialInstanceParameters"), Category="Rendering|Material")
144 ENGINE_API void K2_InterpolateMaterialInstanceParams(UMaterialInstance* SourceA, UMaterialInstance* SourceB, float Alpha);
145
153 UFUNCTION(BlueprintCallable, meta=(DisplayName = "Copy Material Instance Parameters", ScriptName = "CopyMaterialInstanceParameters"), Category="Rendering|Material")
154 ENGINE_API void K2_CopyMaterialInstanceParameters(UMaterialInterface* Source, bool bQuickParametersOnly = false);
155
162 ENGINE_API void CopyMaterialUniformParameters(UMaterialInterface* Source);
163
170 UFUNCTION(meta=(DisplayName = "Copy Interp Parameters"), Category="Rendering|Material")
171 ENGINE_API void CopyInterpParameters(UMaterialInstance* Source);
172
177
184 ENGINE_API void SetFontParameterValue(const FMaterialParameterInfo& ParameterInfo, class UFont* FontValue, int32 FontPage);
185
187 ENGINE_API void ClearParameterValues();
188
193 UFUNCTION(BlueprintCallable, meta=(DisplayName = "Copy Parameter Overrides"), Category="Rendering|Material")
194 ENGINE_API void CopyParameterOverrides(UMaterialInstance* MaterialInstance);
195
200 UE_DEPRECATED(5.7, "Please use CopyScalarAndVectorParameters with EShaderPlatform argument and not ERHIFeatureLevel::Type")
202 ENGINE_API void CopyScalarAndVectorParameters(const UMaterialInterface& SourceMaterialToCopyFrom, EShaderPlatform ShaderPlatform);
203
204 ENGINE_API void SetNaniteOverride(UMaterialInterface* InMaterial);
205
206 virtual bool HasOverridenBaseProperties()const override{ return false; }
207
208 //Material base property overrides. MIDs cannot override these so they just grab from their parent.
209 ENGINE_API virtual float GetOpacityMaskClipValue() const override;
210 ENGINE_API virtual bool GetCastDynamicShadowAsMasked() const override;
211 ENGINE_API virtual FMaterialShadingModelField GetShadingModels() const override;
212 ENGINE_API virtual bool IsShadingModelFromMaterialExpression() const override;
213 ENGINE_API virtual EBlendMode GetBlendMode() const override;
214 ENGINE_API virtual bool IsTwoSided() const override;
215 ENGINE_API virtual bool IsThinSurface() const override;
216 ENGINE_API virtual bool IsTranslucencyWritingVelocity() const override;
217 ENGINE_API virtual bool IsDitheredLODTransition() const override;
218 ENGINE_API virtual bool IsMasked() const override;
219 ENGINE_API virtual FDisplacementScaling GetDisplacementScaling() const override;
220 ENGINE_API virtual bool IsDisplacementFadeEnabled() const override;
221 ENGINE_API virtual FDisplacementFadeRange GetDisplacementFadeRange() const override;
222 ENGINE_API virtual float GetMaxWorldPositionOffsetDisplacement() const override;
223 ENGINE_API virtual bool HasPixelAnimation() const override;
224
230 TMap<FName, TArray<FName> > RenamedTextures;
231
232 // This overrides does the remapping before looking at the parent data.
233 ENGINE_API virtual float GetTextureDensity(FName TextureName, const struct FMeshUVChannelInfo& UVChannelData) const override;
234
235protected:
236
237 ENGINE_API void InitializeMID(class UMaterialInterface* ParentMaterial);
238
239#if !WITH_EDITOR
240 virtual bool CanCacheTexturesSamplingInfo() const override
241 {
242 return false;
243 }
244#endif
245
246private:
247
248 ENGINE_API void UpdateCachedDataDynamic();
249};
250
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
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
EBlendMode
Definition EngineTypes.h:245
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
EShaderPlatform
Definition RHIShaderPlatform.h:11
Definition NameTypes.h:617
Definition UnrealString.h.inl:34
Definition Font.h:111
Definition MaterialInstanceDynamic.h:15
virtual bool CanCacheTexturesSamplingInfo() const override
Definition MaterialInstanceDynamic.h:240
Definition MaterialInstance.h:627
Definition MaterialInterface.h:296
Definition Object.h:95
Definition RuntimeVirtualTexture.h:18
Definition SparseVolumeTexture.h:309
Definition TextureCollection.h:47
Definition Texture.h:1219
Type
Definition RHIFeatureLevel.h:20
Definition EngineTypes.h:3237
Definition EngineTypes.h:3204
Definition Color.h:48
Definition MaterialParameters.h:33
Definition EngineTypes.h:732
Definition MeshUVChannelInfo.h:13