UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MaterialLayersFunctions.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"
9
10#include "MaterialLayersFunctions.generated.h"
11
12#define LOCTEXT_NAMESPACE "MaterialLayersFunctions"
13
14class FArchive;
18
19UENUM()
21{
22 Uninitialized = 0u, // Saved with previous engine version
23 LinkedToParent, // Layer should mirror changes from parent material
24 UnlinkedFromParent, // Layer is based on parent material, but should not mirror changes
25 NotFromParent, // Layer was created locally in this material, not in parent
26};
27
30{
34
35 #if WITH_EDITOR
36 bool operator==(const FMaterialLayersFunctionsID& Reference) const;
37 inline bool operator!=(const FMaterialLayersFunctionsID& Reference) const { return !operator==(Reference); }
38
39 void SerializeForDDC(FArchive& Ar);
40
42 {
43 Ref.SerializeForDDC(Ar);
44 return Ref;
45 }
46
47 void UpdateHash(FSHA1& HashState) const;
48
49 //TODO: Investigate whether this is really required given it is only used by FMaterialShaderMapId AND that one also uses UpdateHash
50 void AppendKeyString(FString& KeyString) const;
51 void Append(FShaderKeyGenerator& KeyGen) const;
52 #endif
53};
54
55USTRUCT()
57{
59
60 UPROPERTY(EditAnywhere, Category = MaterialLayers)
61 TArray<bool> LayerStates;
62
63 UPROPERTY(EditAnywhere, Category = MaterialLayers)
64 TArray<FText> LayerNames;
65
66 UPROPERTY(EditAnywhere, Category = MaterialLayers)
67 TArray<bool> RestrictToLayerRelatives;
68
69 UPROPERTY(EditAnywhere, Category = MaterialLayers)
70 TArray<bool> RestrictToBlendRelatives;
71
73 UPROPERTY(EditAnywhere, Category = MaterialLayers)
74 TArray<FGuid> LayerGuids;
75
79 UPROPERTY(EditAnywhere, Category = MaterialLayers)
81
86 UPROPERTY(EditAnywhere, Category = MaterialLayers)
87 TArray<FGuid> DeletedParentLayerGuids;
88
89#if WITH_EDITORONLY_DATA
90 inline bool operator==(const FMaterialLayersFunctionsEditorOnlyData& Other) const
91 {
92 if (LayerStates != Other.LayerStates ||
93 LayerLinkStates != Other.LayerLinkStates ||
94 DeletedParentLayerGuids != Other.DeletedParentLayerGuids)
95 {
96 return false;
97 }
98 return true;
99 }
100
102 {
103 return !operator==(Other);
104 }
105#endif // WITH_EDITORONLY_DATA
106
107#if WITH_EDITOR
108 void Empty()
109 {
110 LayerStates.Empty();
111 LayerNames.Empty();
112 RestrictToLayerRelatives.Empty();
113 RestrictToBlendRelatives.Empty();
114 LayerGuids.Empty();
115 LayerLinkStates.Empty();
116 }
117
119#endif // WITH_EDITOR
120};
121
123{
124 //Helper struct for managing available layers and blends across parent/instance materials utilising the LayerStack node.
127};
128
129USTRUCT()
131{
133
134 UPROPERTY(EditAnywhere, Category = MaterialLayers)
136
137 UPROPERTY(EditAnywhere, Category = MaterialLayers)
139
140 // In multiple locations there are const references to this runtime data/it's children,
141 // so this mutable entry is required to ensure we can keep available layers/blend up to date across all instances.
143
146 : Layers(Rhs.Layers)
147 , Blends(Rhs.Blends)
148 , LayerStackCache(Rhs.LayerStackCache)
149 {}
150
152
154 {
155 Layers = Rhs.Layers;
156 Blends = Rhs.Blends;
157 LayerStackCache = Rhs.LayerStackCache;
158 return *this;
159 }
160
162
164
165 void Empty()
166 {
167 Layers.Empty();
168 Blends.Empty();
169 LayerStackCache.Reset();
170 }
171
173 {
174 if (Layers != Other.Layers || Blends != Other.Blends)
175 {
176 return false;
177 }
178
179 if (LayerStackCache || Other.LayerStackCache)
180 {
181 if (!LayerStackCache || !Other.LayerStackCache
182 || LayerStackCache->AvailableLayerPaths != Other.LayerStackCache->AvailableLayerPaths
183 || LayerStackCache->AvailableBlendPaths != Other.LayerStackCache->AvailableBlendPaths)
184 {
185 return false;
186 }
187 }
188 return true;
189 }
190
192 {
193 return !operator==(Other);
194 }
195
196 bool SerializeFromMismatchedTag(const FPropertyTag& Tag, FStructuredArchive::FSlot Slot);
197
198#if WITH_EDITOR
200#endif // WITH_EDITOR
201
202#if WITH_EDITORONLY_DATA
203private:
206
207
208
209 friend struct FStaticParameterSet;
210#endif // WITH_EDITORONLY_DATA
211};
212
213template<>
218
219USTRUCT()
221{
223
224#if WITH_EDITOR
226#endif // WITH_EDITOR
227
229
232
234 const FMaterialLayersFunctionsRuntimeData& GetRuntime() const { return *this; }
235
236 UPROPERTY(EditAnywhere, Category = MaterialLayers)
238
239 void Empty()
240 {
242#if WITH_EDITOR
243 EditorOnly.Empty();
244#endif
245 }
246
247 inline bool IsEmpty() const { return Layers.Num() == 0; }
248
249#if WITH_EDITOR
251
253
257 bool bVisible,
259
262 bool bVisible,
264 {
265 return AddLayerCopy(Source, Source.EditorOnly, SourceLayerIndex, bVisible, LinkState);
266 }
267
272 int32 LayerIndex);
273
274 void InsertLayerCopy(const FMaterialLayersFunctions& Source,
277 int32 LayerIndex)
278 {
279 return InsertLayerCopy(Source, Source.EditorOnly, SourceLayerIndex, LinkState, LayerIndex);
280 }
281
283
285
286 const ID GetID() const { return FMaterialLayersFunctionsRuntimeData::GetID(EditorOnly); }
287
291
295 ENGINE_API bool HasAnyUnlinkedLayers() const;
296
298 {
299 if (Index < 0)
300 return;
301 check(EditorOnly.LayerStates.IsValidIndex(Index));
302 EditorOnly.LayerStates[Index] = !EditorOnly.LayerStates[Index];
303 }
304
306 {
307 if (Index < 0)
308 return;
309 check(EditorOnly.LayerStates.IsValidIndex(Index));
310 EditorOnly.LayerStates[Index] = InNewVisibility;
311 }
312
313 bool GetLayerVisibility(int32 Index) const
314 {
315 if (Index < 0)
316 return true;
317 check(EditorOnly.LayerStates.IsValidIndex(Index));
318 return EditorOnly.LayerStates[Index];
319 }
320
321 FText GetLayerName(int32 Counter) const
322 {
323 FText LayerName = FText::Format(LOCTEXT("LayerPrefix", "Layer {0}"), Counter);
324 if (EditorOnly.LayerNames.IsValidIndex(Counter))
325 {
326 LayerName = EditorOnly.LayerNames[Counter];
327 }
328 return LayerName;
329 }
330
332 {
333 EditorOnly.LinkAllLayersToParent();
334 }
335
340
342 {
343 return MatchesParent(GetRuntime(), EditorOnly, Parent.GetRuntime(), Parent.EditorOnly);
344 }
345
351
353 {
354 return FMaterialLayersFunctions::ResolveParent(Parent.GetRuntime(), Parent.EditorOnly, GetRuntime(), EditorOnly, OutRemapLayerIndices);
355 }
356
358
359 void Validate()
360 {
361 Validate(GetRuntime(), EditorOnly);
362 }
363
365
366#endif // WITH_EDITOR
367
368 ENGINE_API void PostSerialize(const FArchive& Ar);
369
370 inline bool operator==(const FMaterialLayersFunctions& Other) const
371 {
372 if (!FMaterialLayersFunctionsRuntimeData::operator==(Other))
373 {
374 return false;
375 }
376#if WITH_EDITORONLY_DATA
377 if (EditorOnly != Other.EditorOnly)
378 {
379 return false;
380 }
381#endif // WITH_EDITORONLY_DATA
382 return true;
383 }
384
385 inline bool operator!=(const FMaterialLayersFunctions& Other) const
386 {
387 return !operator==(Other);
388 }
389
390private:
391 UPROPERTY()
392 TArray<bool> LayerStates_DEPRECATED;
393
394 UPROPERTY()
395 TArray<FText> LayerNames_DEPRECATED;
396
397 UPROPERTY()
398 TArray<bool> RestrictToLayerRelatives_DEPRECATED;
399
400 UPROPERTY()
401 TArray<bool> RestrictToBlendRelatives_DEPRECATED;
402
403 UPROPERTY()
404 TArray<FGuid> LayerGuids_DEPRECATED;
405
406 UPROPERTY()
407 TArray<EMaterialLayerLinkState> LayerLinkStates_DEPRECATED;
408
409 UPROPERTY()
410 TArray<FGuid> DeletedParentLayerGuids_DEPRECATED;
411
412
413 // Don't allowing comparing a full FMaterialLayersFunctions against partial RuntimeData
418};
419
420template<>
425
426#undef LOCTEXT_NAMESPACE
#define check(expr)
Definition AssertionMacros.h:314
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
FArchive & operator<<(FArchive &Ar, FEnvQueryDebugProfileData::FStep &Data)
Definition EnvQueryTypes.cpp:489
#define LOCTEXT(InKey, InTextLiteral)
Definition Internationalization.h:295
UE_FORCEINLINE_HINT bool operator!=(const FIndexedPointer &Other) const
Definition LockFreeList.h:76
EMaterialLayerLinkState
Definition MaterialLayersFunctions.h:21
void SerializeLegacy(FArchive &Ar, FAttributesSetBase &AttributesSet)
Definition MeshAttributeArray.cpp:41
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UENUM(...)
Definition ObjectMacros.h:749
#define USTRUCT(...)
Definition ObjectMacros.h:746
#define GENERATED_USTRUCT_BODY(...)
Definition ObjectMacros.h:767
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition Archive.h:1208
Definition SecureHash.h:314
Definition ShaderKeyGenerator.h:29
Definition StructuredArchiveSlots.h:52
Definition Text.h:385
static CORE_API FText Format(FTextFormat Fmt, const FFormatNamedArguments &InArguments)
Definition Text.cpp:469
Definition Array.h:670
Definition SharedPointer.h:692
Definition UniquePtr.h:107
Definition MaterialExpressionMaterialFunctionCall.h:81
Definition MaterialFunctionInterface.h:59
void PostSerialize(const FArchive &Ar, void *Data)
Definition Class.h:1300
TWeakInterfacePtr< INNERuntime > GetRuntime(const FString &Name)
Definition NNE.cpp:102
U16 Index
Definition radfft.cpp:71
Definition Guid.h:109
Definition MaterialLayersFunctions.h:123
TArray< FSoftObjectPath > AvailableBlendPaths
Definition MaterialLayersFunctions.h:126
TArray< FSoftObjectPath > AvailableLayerPaths
Definition MaterialLayersFunctions.h:125
Definition MaterialLayersFunctions.h:57
Definition MaterialLayersFunctions.h:30
TArray< FGuid > BlendIDs
Definition MaterialLayersFunctions.h:32
TArray< bool > LayerStates
Definition MaterialLayersFunctions.h:33
TArray< FGuid > LayerIDs
Definition MaterialLayersFunctions.h:31
Definition MaterialLayersFunctions.h:131
bool operator!=(const FMaterialLayersFunctionsRuntimeData &Other) const
Definition MaterialLayersFunctions.h:191
bool operator==(const FMaterialLayersFunctionsRuntimeData &Other) const
Definition MaterialLayersFunctions.h:172
FMaterialLayersFunctionsRuntimeData & operator=(const FMaterialLayersFunctions &Rhs)=delete
void Empty()
Definition MaterialLayersFunctions.h:165
FMaterialLayersFunctionsRuntimeData & operator=(const FMaterialLayersFunctionsRuntimeData &Rhs)
Definition MaterialLayersFunctions.h:153
FMaterialLayersFunctionsRuntimeData(const FMaterialLayersFunctions &Rhs)=delete
Definition MaterialLayersFunctions.h:221
bool IsEmpty() const
Definition MaterialLayersFunctions.h:247
bool operator!=(const FMaterialLayersFunctions &Other) const
Definition MaterialLayersFunctions.h:385
FMaterialLayersFunctions()=default
bool operator==(const FMaterialLayersFunctions &Other) const
Definition MaterialLayersFunctions.h:370
static ENGINE_API const FGuid BackgroundGuid
Definition MaterialLayersFunctions.h:228
FMaterialLayersFunctionsRuntimeData & GetRuntime()
Definition MaterialLayersFunctions.h:233
FMaterialLayersFunctions(const FMaterialLayersFunctionsRuntimeData &)=delete
const FMaterialLayersFunctionsRuntimeData & GetRuntime() const
Definition MaterialLayersFunctions.h:234
Definition PropertyTag.h:38
Definition StaticParameterSet.h:462
Definition ObjectPtr.h:488
Definition StructOpsTypeTraits.h:11
@ WithStructuredSerializeFromMismatchedTag
Definition StructOpsTypeTraits.h:29
Definition StructOpsTypeTraits.h:46