Material layer instances do not generate a valid UMaterialFunctionInterface::StateId.
For this reason, materials and material instances that use material layer instances will not recompile their shaders even if the material layer has changed.
Here's a workaround
MaterialExpressions.cpp
#if WITH_EDITOR //workaround begin void UMaterialFunctionInstance::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) { StateId = Parent ? Parent->StateId : FGuid(); Super::PostEditChangeProperty(PropertyChangedEvent); } //workaround end #endif // WITH_EDITOR void UMaterialFunctionInstance::PostLoad() { Super::PostLoad(); if (Parent) { Parent->ConditionalPostLoad(); StateId = Parent->StateId; //workaround } }
MaterialFunctionInstance.h
class UMaterialFunctionInstance : public UMaterialFunctionInterface { ... virtual bool ValidateFunctionUsage(class FMaterialCompiler* Compiler, const FFunctionExpressionOutput& Output) override; #if WITH_EDITOR //workaround begin virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override; #endif // WITH_EDITOR //workaround end virtual void PostLoad() override;
MaterialEditingLibrary.cpp
void UMaterialEditingLibrary::UpdateMaterialFunction(UMaterialFunctionInterface* MaterialFunction, UMaterial* PreviewMaterial) { ... // Go through all function instances in memory and update them if they are children for (TObjectIterator<UMaterialFunctionInstance> It; It; ++It) { UMaterialFunctionInstance* FunctionInstance = *It; TArray<UMaterialFunctionInterface*> Functions; FunctionInstance->GetDependentFunctions(Functions); if (Functions.Contains(MaterialFunction)) { FunctionInstance->UpdateParameterSet(); FunctionInstance->PostEditChange(); //workaround FunctionInstance->MarkPackageDirty(); } }
The workaround copies StateId from parent material layer.
i have this problem UE4CC-Windows-58DC12AF4B97F057BD108FBFF569B2E9_0000
I am not able to find world outliner how to enable it?
How does UMG set overlapping layouts?
How to achieve HLSL Multiple Render Target in Material blueprints?
How to properly terminate the DoWork thread function in FAsyncTask?
How does TextureRenderTarget2D get TArray<uint8> type data?
How can PaintContext be used as function parameter in OnPaint?
Why doesn't the collision diminish when the collision radius decreases?
Why does the REMOVE method of map container remove elements have memory leaks?
There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-138666 in the post.
2 |
Component | UE - Rendering Architecture - Materials |
---|---|
Affects Versions | 4.26, 5.0-early access 2 |
Created | Jan 7, 2022 |
---|---|
Updated | Sep 22, 2022 |