Material Instance Dynamic as a blendable and updating Parameters *Found work-around*

In my code I am creating a Material Instance Dynamic from a pre-existing material, then adding that Material Instance Dynamic as a blendable onto a PostProcessVolume. The problem I am having is that I am unable to update a scalar value in a Material Parameter Collection that is inside the MID and it only ever uses the default value (which is then applied correctly).

Oddly enough the function calls to set the scalar parameter value and get it seem to work, and the value does actually update since I can display the scalar parameter value on-screen as a debug message. The problem is that MID then doesn’t seem to use that value and only whatever the default is set to.

In my header file I have:

	UPROPERTY(BlueprintReadOnly, Category = Material)
		UMaterialInstanceDynamic* MIDFade;

	UPROPERTY(BlueprintReadOnly, Category = Material)
		UMaterial* MFade;

And then inside the constructor:

	//Find the shader material and create a reference to it
	static ConstructorHelpers::FObjectFinder<UMaterial> TempFadeShader(TEXT("/Game/Materials/FadeShader"));
	if (TempFadeShader.Succeeded())
	{
		MFade = TempFadeShader.Object;
	}

And finally in the PostInitializeComponents function:

	//Create a material instance dynamic from the Material
	MIDFade = UMaterialInstanceDynamic::Create(MFade, this);

	//Set the AlphaBlend value to something to test that it works
	MIDFade->SetScalarParameterValue(FName(TEXT("AlphaBlend")), 1.0f);

	float outBlendValue;
	FString BlendValue;

	//Find the post-process volume in the scene, there is only one in the scene.
	for (TActorIterator<APostProcessVolume> ActorItr(GetWorld()); ActorItr; ++ActorItr)
	{
		ActorItr->bEnabled = true;

		//Add the MID as a blendable
		ActorItr->AddOrUpdateBlendable(MIDFade);
	}

	//Get the AlphaBlend value in the MID and display it on-screen
	if (MIDFade->GetScalarParameterValue(FName(TEXT("AlphaBlend")), outBlendValue))
	{
		BlendValue = FString::SanitizeFloat(outBlendValue);
		GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "AlphaBlend Value: " + BlendValue);
	}

And for completeness sake here is the FadeShader Material itself:

This PostProcess material should just simply fade the screen to a specific colour, and the strength of the fade is based on the AlphaBlend parameter. Any help with this will be appreciated, thanks a lot!

Okay I’ve managed to find a work-around to this problem. Instead of trying to change the parameter through the Material Instance Dynamic, I’m directly editing the Material Parameter Collection itself. To do this I made a reference to the MPC in the class and also included the “Kismet/KismetMaterialLibrary.h” file, which gives me access to the SetScalarParameterValue function. This function can then edit the MPC value directly, which then in turn updates the blendable MID. Not sure if this is the intended method of going about this, but it works.

Would you be able to share what you did? I am not seeing the MPC you are referring to.

This is where I am at Only able to set Material Instance in Begin Play

I would still be interested in what you did, however I figured out my issue. I am able to change the mesh. It was a replication issue for me.